diff --git a/src/app/api/customer/DocumentsController.ts b/src/app/api/customer/DocumentsController.ts index 419062dc..85b64290 100644 --- a/src/app/api/customer/DocumentsController.ts +++ b/src/app/api/customer/DocumentsController.ts @@ -33,7 +33,7 @@ export default class DocumentsController extends ApiController { //success this.httpSuccess(response, documents); } catch (error) { - this.httpBadRequest(response, error); + this.httpInternalError(response); return; } } @@ -62,7 +62,7 @@ export default class DocumentsController extends ApiController { //success this.httpSuccess(response, document); } catch (error) { - this.httpBadRequest(response, error); + this.httpInternalError(response); return; } } @@ -79,6 +79,13 @@ export default class DocumentsController extends ApiController { return; } + const documentFound = await this.documentsService.getByUid(uid); + + if (!documentFound) { + this.httpNotFoundRequest(response, "document not found"); + return; + } + //init Document resource with request body values const documentEntity = new Document(); Document.hydrate(documentEntity, req.body); @@ -95,7 +102,7 @@ export default class DocumentsController extends ApiController { //success this.httpSuccess(response, document); } catch (error) { - this.httpBadRequest(response, error); + this.httpInternalError(response); return; } } @@ -112,16 +119,23 @@ export default class DocumentsController extends ApiController { return; } + const documentEntity = await this.documentsService.getByUid(uid); + + if (!documentEntity) { + this.httpNotFoundRequest(response, "document not found"); + return; + } + //call service to get prisma entity - const documentEntity: Documents = await this.documentsService.delete(uid); + const documentEntityDeleted: Documents = await this.documentsService.delete(uid); //Hydrate ressource with prisma entity - const document = Document.hydrate(documentEntity, { strategy: "excludeAll" }); + const document = Document.hydrate(documentEntityDeleted, { strategy: "excludeAll" }); //success this.httpSuccess(response, document); } catch (error) { - this.httpBadRequest(response, error); + this.httpInternalError(response); return; } } @@ -159,7 +173,7 @@ export default class DocumentsController extends ApiController { //success this.httpSuccess(response, document); } catch (error) { - this.httpBadRequest(response, error); + this.httpInternalError(response); return; } } diff --git a/src/app/api/super-admin/CustomersController.ts b/src/app/api/super-admin/CustomersController.ts index 641fa2ef..96e1b7b6 100644 --- a/src/app/api/super-admin/CustomersController.ts +++ b/src/app/api/super-admin/CustomersController.ts @@ -56,7 +56,7 @@ export default class CustomersController extends ApiController { }); //success - this.httpSuccess(response, customer); + this.httpCreated(response, customer); } catch (error) { this.httpInternalError(response); return; @@ -74,6 +74,14 @@ export default class CustomersController extends ApiController { this.httpBadRequest(response, "No uid provided"); return; } + + const userFound = await this.customersService.getByUid(uid); + + if (!userFound) { + this.httpNotFoundRequest(response, "user not found"); + return; + } + //init IUser resource with request body values const customerEntity = Customer.hydrate(req.body); diff --git a/src/app/api/super-admin/DeedTypesController.ts b/src/app/api/super-admin/DeedTypesController.ts index ba9c6e03..974a0d88 100644 --- a/src/app/api/super-admin/DeedTypesController.ts +++ b/src/app/api/super-admin/DeedTypesController.ts @@ -59,7 +59,7 @@ export default class DeedTypesController extends ApiController { }); //success - this.httpSuccess(response, deedType); + this.httpCreated(response, deedType); } catch (error) { this.httpInternalError(response); return; @@ -78,6 +78,14 @@ export default class DeedTypesController extends ApiController { this.httpBadRequest(response, "No uid provided"); return; } + + const deedTypeFound = await this.deedTypesService.getByUid(uid); + + if (!deedTypeFound) { + this.httpNotFoundRequest(response, "deed type not found"); + return; + } + //init DeedType resource with request body values const deedTypeEntity = DeedType.hydrate(req.body); diff --git a/src/app/api/super-admin/DeedsController.ts b/src/app/api/super-admin/DeedsController.ts index 676c5f79..d03d3ee8 100644 --- a/src/app/api/super-admin/DeedsController.ts +++ b/src/app/api/super-admin/DeedsController.ts @@ -87,6 +87,14 @@ export default class DeedsController extends ApiController { this.httpBadRequest(response, "No uid provided"); return; } + + const deedFound = await this.deedsService.getByUid(uid); + + if (!deedFound) { + this.httpNotFoundRequest(response, "deed not found"); + return; + } + //init OfficeFolder resource with request body values const deedEntity = Deed.hydrate(req.body); diff --git a/src/app/api/super-admin/DocumentTypesController.ts b/src/app/api/super-admin/DocumentTypesController.ts index 802ffcf6..d03c37ae 100644 --- a/src/app/api/super-admin/DocumentTypesController.ts +++ b/src/app/api/super-admin/DocumentTypesController.ts @@ -57,7 +57,7 @@ export default class DocumentTypesController extends ApiController { strategy: "excludeAll", }); //success - this.httpSuccess(response, userEntityCreated); + this.httpCreated(response, userEntityCreated); } catch (error) { this.httpInternalError(response); return; @@ -75,6 +75,13 @@ export default class DocumentTypesController extends ApiController { this.httpBadRequest(response, "No uid provided"); return; } + + const documentTypeFound = await this.documentTypesService.getByUid(uid); + + if (!documentTypeFound) { + this.httpNotFoundRequest(response, "document type not found"); + return; + } //init DocumentType resource with request body values const documentTypeEntity = DocumentType.hydrate(req.body); diff --git a/src/app/api/super-admin/DocumentsController.ts b/src/app/api/super-admin/DocumentsController.ts index 0a83078b..59ee08e5 100644 --- a/src/app/api/super-admin/DocumentsController.ts +++ b/src/app/api/super-admin/DocumentsController.ts @@ -60,7 +60,7 @@ export default class DocumentsController extends ApiController { }); //success - this.httpSuccess(response, document); + this.httpCreated(response, document); } catch (error) { this.httpInternalError(response); return; @@ -77,7 +77,14 @@ export default class DocumentsController extends ApiController { if (!uid) { this.httpBadRequest(response, "No uid provided"); return; - } + } + + const documentFound = await this.documentsService.getByUid(uid); + + if (!documentFound) { + this.httpNotFoundRequest(response, "document not found"); + return; + } //init Document resource with request body values const documentEntity = Document.hydrate(req.body); @@ -111,6 +118,13 @@ export default class DocumentsController extends ApiController { return; } + const documentFound = await this.documentsService.getByUid(uid); + + if (!documentFound) { + this.httpNotFoundRequest(response, "document not found"); + return; + } + //call service to get prisma entity const documentEntity: Documents = await this.documentsService.delete(uid); diff --git a/src/app/api/super-admin/FilesController.ts b/src/app/api/super-admin/FilesController.ts index eb50b90b..745bac2a 100644 --- a/src/app/api/super-admin/FilesController.ts +++ b/src/app/api/super-admin/FilesController.ts @@ -53,7 +53,7 @@ export default class FilesController extends ApiController { const fileInfo = await this.filesService.download(uid); if (!fileInfo) { - this.httpNotFoundRequest(response); + this.httpNotFoundRequest(response, "file not found"); return; } @@ -103,7 +103,7 @@ export default class FilesController extends ApiController { }); //success - this.httpSuccess(response, fileEntityHydrated); + this.httpCreated(response, fileEntityHydrated); } catch (error) { this.httpBadRequest(response, error); return; @@ -121,6 +121,13 @@ export default class FilesController extends ApiController { throw new Error("No uid provided"); } + const fileFound = await this.filesService.getByUid(uid); + + if (!fileFound) { + this.httpNotFoundRequest(response, "file not found"); + return; + } + //init File resource with request body values const fileEntity = File.hydrate(req.body); @@ -153,6 +160,13 @@ export default class FilesController extends ApiController { return; } + const fileFound = await this.filesService.getByUid(uid); + + if (!fileFound) { + this.httpNotFoundRequest(response, "file not found"); + return; + } + //call service to get prisma entity const fileEntity = await this.filesService.deleteKeyAndArchive(uid); diff --git a/src/app/api/super-admin/OfficeFoldersController.ts b/src/app/api/super-admin/OfficeFoldersController.ts index 7bd245b3..4c642835 100644 --- a/src/app/api/super-admin/OfficeFoldersController.ts +++ b/src/app/api/super-admin/OfficeFoldersController.ts @@ -54,7 +54,7 @@ export default class OfficeFoldersController extends ApiController { strategy: "excludeAll", }); //success - this.httpSuccess(response, officeFolders); + this.httpCreated(response, officeFolders); } catch (error) { this.httpInternalError(response); return; @@ -72,6 +72,14 @@ export default class OfficeFoldersController extends ApiController { this.httpBadRequest(response, "No uid provided"); return; } + + const officeFolderFound = await this.officeFoldersService.getByUid(uid); + + if (!officeFolderFound) { + this.httpNotFoundRequest(response, "office folder not found"); + return; + } + //init OfficeFolder resource with request body values const officeFolderEntity = OfficeFolder.hydrate(req.body); @@ -146,6 +154,13 @@ export default class OfficeFoldersController extends ApiController { return; } + const officeFolderFound = await this.officeFoldersService.getByUid(uid); + + if (!officeFolderFound) { + this.httpNotFoundRequest(response, "office folder not found"); + return; + } + //call service to get prisma entity const officeFoldertEntity: OfficeFolders = await this.officeFoldersService.delete(uid); diff --git a/src/app/api/super-admin/OfficesController.ts b/src/app/api/super-admin/OfficesController.ts index 397cdba5..820ccade 100644 --- a/src/app/api/super-admin/OfficesController.ts +++ b/src/app/api/super-admin/OfficesController.ts @@ -49,7 +49,7 @@ export default class OfficesController extends ApiController { strategy: "excludeAll", }); //success - this.httpSuccess(response, office); + this.httpCreated(response, office); } catch (error) { this.httpInternalError(response); return; @@ -66,6 +66,13 @@ export default class OfficesController extends ApiController { this.httpBadRequest(response, "No uid provided"); return; } + + const officeFound = await this.officesService.getByUid(uid); + + if (!officeFound) { + this.httpNotFoundRequest(response, "office not found"); + return; + } //init IUser resource with request body values const officeEntity = OfficeResource.hydrate(req.body); //validate user diff --git a/src/app/api/super-admin/UsersController.ts b/src/app/api/super-admin/UsersController.ts index c0ff65ff..7ba6f437 100644 --- a/src/app/api/super-admin/UsersController.ts +++ b/src/app/api/super-admin/UsersController.ts @@ -58,7 +58,7 @@ export default class UsersController extends ApiController { }); //success - this.httpSuccess(response, user); + this.httpCreated(response, user); } catch (error) { this.httpInternalError(response); return; @@ -76,6 +76,14 @@ export default class UsersController extends ApiController { this.httpBadRequest(response, "No uid provided"); return; } + + const userFound = await this.usersService.getByUid(uid); + + if (!userFound) { + this.httpNotFoundRequest(response, "user not found"); + return; + } + //init IUser resource with request body values const userEntity = User.hydrate(req.body); diff --git a/src/common/system/controller-pattern/BaseController.ts b/src/common/system/controller-pattern/BaseController.ts index 24906610..27eb5aa9 100644 --- a/src/common/system/controller-pattern/BaseController.ts +++ b/src/common/system/controller-pattern/BaseController.ts @@ -28,7 +28,7 @@ export default abstract class BaseController { return this.httpResponse(response, HttpCodes.INTERNAL_ERROR, responseData); } - protected httpNotImplemented(response: Response, responseData: IResponseData = "http Internal Server Error") { + protected httpNotImplemented(response: Response, responseData: IResponseData = "Not implemented") { return this.httpResponse(response, HttpCodes.NOT_IMPLEMENTED, responseData); }