Skip to content

Commit 36ae2a2

Browse files
Tony QiuTony Qiu
authored andcommitted
fix linit
1 parent d2b4109 commit 36ae2a2

File tree

2 files changed

+48
-26
lines changed

2 files changed

+48
-26
lines changed

backend/typescript/rest/entityRoutes.ts

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ import multer from "multer";
44
// import { isAuthorizedByRole } from "@/middlewares/auth";
55
import { entityRequestDtoValidator } from "@/middlewares/validators/entityValidators";
66
// import EntityService from "@/services/implementations/entityService";
7+
import entityServiceMock from "@/services/implementations/entityServiceMock";
78
// import FileStorageService from "@/services/implementations/fileStorageService";
89
// import { IFileStorageService } from "@/services/interfaces/IFileStorageService";
9-
import {
10-
EntityResponseDTO,
11-
IEntityService,
12-
} from "@/services/interfaces/IEntityService";
10+
import { EntityResponseDTO } from "@/services/interfaces/IEntityService";
1311
import { getErrorMessage } from "@/utilities/errorUtils";
1412
import { sendResponseByMimeType } from "@/utilities/responseUtil";
1513

@@ -25,28 +23,7 @@ const defaultBucket = process.env.FIREBASE_STORAGE_DEFAULT_BUCKET || "";
2523
// defaultBucket,
2624
// );
2725
// const entityService: IEntityService = new EntityService(fileStorageService);
28-
29-
// Mock Service
30-
let memoryStore: Record<string, unknown> = {};
31-
const entityService: IEntityService = {
32-
createEntity: async (entity) => {
33-
memoryStore = { id: "1", ...entity };
34-
return memoryStore;
35-
},
36-
updateEntity: async (id, entity) => {
37-
memoryStore = { id, ...entity };
38-
return memoryStore;
39-
},
40-
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
41-
getEntity: async (id) => {
42-
return memoryStore;
43-
},
44-
getEntities: async () => [memoryStore],
45-
deleteEntity: async (id) => {
46-
memoryStore = {};
47-
return id;
48-
},
49-
};
26+
const entityService = entityServiceMock;
5027

5128
/* Create entity */
5229
entityRouter.post(
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import {
2+
EntityRequestDTO,
3+
EntityResponseDTO,
4+
IEntityService,
5+
} from "@/services/interfaces/IEntityService";
6+
7+
function requestToResponse(
8+
id: string,
9+
entity: EntityRequestDTO,
10+
): EntityResponseDTO {
11+
return {
12+
id,
13+
stringField: entity.stringField,
14+
intField: entity.intField,
15+
enumField: entity.enumField,
16+
stringArrayField: entity.stringArrayField,
17+
boolField: entity.boolField,
18+
fileName: entity.filePath ?? "",
19+
};
20+
}
21+
22+
let memoryStore: EntityResponseDTO | null = null;
23+
24+
const entityServiceMock: IEntityService = {
25+
createEntity: async (entity) => {
26+
memoryStore = requestToResponse("1", entity);
27+
return memoryStore;
28+
},
29+
updateEntity: async (id, entity) => {
30+
memoryStore = requestToResponse(id, entity);
31+
return memoryStore;
32+
},
33+
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
34+
getEntity: async (id) => {
35+
if (!memoryStore) throw new Error(`Entity id ${id} not found`);
36+
return memoryStore;
37+
},
38+
getEntities: async () => (memoryStore ? [memoryStore] : []),
39+
deleteEntity: async (id) => {
40+
memoryStore = null;
41+
return id;
42+
},
43+
};
44+
45+
export default entityServiceMock;

0 commit comments

Comments
 (0)