@@ -24,6 +24,27 @@ const defaultBucket = process.env.FIREBASE_STORAGE_DEFAULT_BUCKET || "";
2424// );
2525// const entityService: IEntityService = new EntityService(fileStorageService);
2626
27+ // Mock Service
28+ let memoryStore : any = { } ;
29+ const entityService : IEntityService = {
30+ createEntity : async ( entity ) => {
31+ memoryStore = { id : "1" , ...entity } ;
32+ return memoryStore ;
33+ } ,
34+ updateEntity : async ( id , entity ) => {
35+ memoryStore = { id, ...entity } ;
36+ return memoryStore ;
37+ } ,
38+ getEntity : async ( id ) => {
39+ return memoryStore ;
40+ } ,
41+ getEntities : async ( ) => [ memoryStore ] ,
42+ deleteEntity : async ( id ) => {
43+ memoryStore = { } ;
44+ return id ;
45+ } ,
46+ } ;
47+
2748/* Create entity */
2849entityRouter . post (
2950 "/" ,
@@ -32,19 +53,19 @@ entityRouter.post(
3253 async ( req , res ) => {
3354 try {
3455 const body = JSON . parse ( req . body . body ) ;
35- // const newEntity = await entityService.createEntity({
36- // stringField: body.stringField,
37- // intField: body.intField,
38- // enumField: body.enumField,
39- // stringArrayField: body.stringArrayField,
40- // boolField: body.boolField,
41- // filePath: req.file?.path,
42- // fileContentType: req.file?.mimetype,
43- // });
56+ const newEntity = await entityService . createEntity ( {
57+ stringField : body . stringField ,
58+ intField : body . intField ,
59+ enumField : body . enumField ,
60+ stringArrayField : body . stringArrayField ,
61+ boolField : body . boolField ,
62+ filePath : req . file ?. path ,
63+ fileContentType : req . file ?. mimetype ,
64+ } ) ;
4465 if ( req . file ?. path ) {
4566 fs . unlinkSync ( req . file . path ) ;
4667 }
47- // res.status(201).json(newEntity);
68+ res . status ( 201 ) . json ( newEntity ) ;
4869 } catch ( e : unknown ) {
4970 res . status ( 500 ) . send ( getErrorMessage ( e ) ) ;
5071 }
@@ -55,13 +76,13 @@ entityRouter.post(
5576entityRouter . get ( "/" , async ( req , res ) => {
5677 const contentType = req . headers [ "content-type" ] ;
5778 try {
58- // const entities = await entityService.getEntities();
59- // await sendResponseByMimeType<EntityResponseDTO>(
60- // res,
61- // 200,
62- // contentType,
63- // entities,
64- // );
79+ const entities = await entityService . getEntities ( ) ;
80+ await sendResponseByMimeType < EntityResponseDTO > (
81+ res ,
82+ 200 ,
83+ contentType ,
84+ entities ,
85+ ) ;
6586 } catch ( e : unknown ) {
6687 await sendResponseByMimeType ( res , 500 , contentType , [
6788 {
@@ -76,8 +97,8 @@ entityRouter.get("/:id", async (req, res) => {
7697 const { id } = req . params ;
7798
7899 try {
79- // const entity = await entityService.getEntity(id);
80- // res.status(200).json(entity);
100+ const entity = await entityService . getEntity ( id ) ;
101+ res . status ( 200 ) . json ( entity ) ;
81102 } catch ( e : unknown ) {
82103 res . status ( 500 ) . send ( getErrorMessage ( e ) ) ;
83104 }
@@ -92,19 +113,19 @@ entityRouter.put(
92113 const { id } = req . params ;
93114 try {
94115 const body = JSON . parse ( req . body . body ) ;
95- // const entity = await entityService.updateEntity(id, {
96- // stringField: body.stringField,
97- // intField: body.intField,
98- // enumField: body.enumField,
99- // stringArrayField: body.stringArrayField,
100- // boolField: body.boolField,
101- // filePath: req.file?.path,
102- // fileContentType: req.file?.mimetype,
103- // });
116+ const entity = await entityService . updateEntity ( id , {
117+ stringField : body . stringField ,
118+ intField : body . intField ,
119+ enumField : body . enumField ,
120+ stringArrayField : body . stringArrayField ,
121+ boolField : body . boolField ,
122+ filePath : req . file ?. path ,
123+ fileContentType : req . file ?. mimetype ,
124+ } ) ;
104125 if ( req . file ?. path ) {
105126 fs . unlinkSync ( req . file . path ) ;
106127 }
107- // res.status(200).json(entity);
128+ res . status ( 200 ) . json ( entity ) ;
108129 } catch ( e : unknown ) {
109130 res . status ( 500 ) . send ( getErrorMessage ( e ) ) ;
110131 }
@@ -116,8 +137,8 @@ entityRouter.delete("/:id", async (req, res) => {
116137 const { id } = req . params ;
117138
118139 try {
119- // const deletedId = await entityService.deleteEntity(id);
120- // res.status(200).json({ id: deletedId });
140+ const deletedId = await entityService . deleteEntity ( id ) ;
141+ res . status ( 200 ) . json ( { id : deletedId } ) ;
121142 } catch ( e : unknown ) {
122143 res . status ( 500 ) . send ( getErrorMessage ( e ) ) ;
123144 }
@@ -127,8 +148,8 @@ entityRouter.delete("/:id", async (req, res) => {
127148entityRouter . get ( "/files/:fileUUID" , async ( req , res ) => {
128149 const { fileUUID } = req . params ;
129150 try {
130- // const fileURL = await fileStorageService.getFile(fileUUID) ;
131- // res.status(200).json({ fileURL });
151+ const fileURL = "http://fake-storage.com/dummy.txt" ;
152+ res . status ( 200 ) . json ( { fileURL } ) ;
132153 } catch ( e : unknown ) {
133154 res . status ( 500 ) . send ( getErrorMessage ( e ) ) ;
134155 }
0 commit comments