add created http code and notFoundErrors on put and delete

This commit is contained in:
OxSaitama 2023-05-15 12:07:08 +02:00
parent 2cf1067f03
commit 71b39d6e55
11 changed files with 121 additions and 18 deletions

View File

@ -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<Document>(documentEntity, { strategy: "excludeAll" });
const document = Document.hydrate<Document>(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;
}
}

View File

@ -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<Customer>(req.body);

View File

@ -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<DeedType>(req.body);

View File

@ -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<Deed>(req.body);

View File

@ -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<DocumentType>(req.body);

View File

@ -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;
@ -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 = Document.hydrate<Document>(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);

View File

@ -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<File>(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);

View File

@ -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<OfficeFolder>(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);

View File

@ -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<OfficeResource>(req.body);
//validate user

View File

@ -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<User>(req.body);

View File

@ -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);
}