refacto errors and naming (#44)
refacto errors: add http errors and status renaming: entities variables declaration and hydrate arrays method
This commit is contained in:
commit
dcb7052a32
@ -48,7 +48,7 @@
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.18.2",
|
||||
"jsonwebtoken": "^9.0.0",
|
||||
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.47",
|
||||
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.49",
|
||||
"module-alias": "^2.2.2",
|
||||
"multer": "^1.4.5-lts.1",
|
||||
"next": "^13.1.5",
|
||||
|
@ -25,15 +25,15 @@ export default class DocumentsController extends ApiController {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntity: Documents[] = await this.documentsService.get(query);
|
||||
const documentEntities: Documents[] = await this.documentsService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const documents = Document.map<Document>(Document, prismaEntity, { strategy: "excludeAll" });
|
||||
const documents = Document.hydrateArray<Document>(Document, documentEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, documents);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -52,17 +52,17 @@ export default class DocumentsController extends ApiController {
|
||||
await validateOrReject(documentEntity, { groups: ["createDocument"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityCreated = await this.documentsService.create(documentEntity);
|
||||
const documentEntityCreated = await this.documentsService.create(documentEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const documentEntityCreated = Document.hydrate<Document>(prismaEntityCreated, {
|
||||
const document = Document.hydrate<Document>(documentEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, documentEntityCreated);
|
||||
this.httpSuccess(response, document);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -75,7 +75,15 @@ export default class DocumentsController extends ApiController {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
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
|
||||
@ -86,15 +94,15 @@ export default class DocumentsController extends ApiController {
|
||||
await validateOrReject(documentEntity, { groups: ["createDocument"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity);
|
||||
const documentEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const document = Document.hydrate<Document>(prismaEntityUpdated, { strategy: "excludeAll" });
|
||||
const document = Document.hydrate<Document>(documentEntityUpdated, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, document);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -107,19 +115,27 @@ export default class DocumentsController extends ApiController {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -132,10 +148,11 @@ export default class DocumentsController extends ApiController {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
let documentEntity: Documents;
|
||||
let documentEntity: Documents | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
@ -145,13 +162,18 @@ export default class DocumentsController extends ApiController {
|
||||
documentEntity = await this.documentsService.getByUid(uid);
|
||||
}
|
||||
|
||||
if (!documentEntity) {
|
||||
this.httpNotFoundRequest(response, "document not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const document = Document.hydrate<Document>(documentEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, document);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ import AuthService from "@Services/private-services/AuthService/AuthService";
|
||||
//success
|
||||
this.httpSuccess(response, user);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -24,15 +24,15 @@ export default class CustomersController extends ApiController {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
|
||||
//call service to get prisma entity
|
||||
const customersEntity = await this.customersService.get(query);
|
||||
const customersEntities = await this.customersService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const customers = Customer.map<Customer>(Customer, customersEntity, { strategy: "excludeAll" });
|
||||
const customers = Customer.hydrateArray<Customer>(Customer, customersEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, customers);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -49,16 +49,16 @@ export default class CustomersController extends ApiController {
|
||||
await validateOrReject(customerEntity, { groups: ["createCustomer"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityCreated = await this.customersService.create(customerEntity);
|
||||
const customerEntityCreated = await this.customersService.create(customerEntity);
|
||||
//Hydrate ressource with prisma entity
|
||||
const customerEntityCreated = Customer.hydrate<Customer>(prismaEntityCreated, {
|
||||
const customer = Customer.hydrate<Customer>(customerEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, customerEntityCreated);
|
||||
this.httpCreated(response, customer);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -71,8 +71,17 @@ export default class CustomersController extends ApiController {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
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);
|
||||
|
||||
@ -80,17 +89,17 @@ export default class CustomersController extends ApiController {
|
||||
await validateOrReject(customerEntity, { groups: ["updateCustomer"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityUpdated = await this.customersService.update(uid, customerEntity);
|
||||
const customerEntityUpdated = await this.customersService.update(uid, customerEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const customerEntityUpdated = Customer.hydrate<Customer>(prismaEntityUpdated, {
|
||||
const customer = Customer.hydrate<Customer>(customerEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, customerEntityUpdated);
|
||||
this.httpSuccess(response, customer);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -103,10 +112,11 @@ export default class CustomersController extends ApiController {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
let customerEntity: Customers;
|
||||
let customerEntity: Customers | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
@ -116,13 +126,18 @@ export default class CustomersController extends ApiController {
|
||||
customerEntity = await this.customersService.getByUid(uid);
|
||||
}
|
||||
|
||||
if (!customerEntity) {
|
||||
this.httpNotFoundRequest(response, "customer not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const customer = Customer.hydrate<Customer>(customerEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, customer);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -24,15 +24,15 @@ export default class DeedTypesController extends ApiController {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
//call service to get prisma entity
|
||||
const prismaEntity: DeedTypes[] = await this.deedTypesService.get(query);
|
||||
const deedTypeEntities: DeedTypes[] = await this.deedTypesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const DeedTypes = DeedType.map<DeedType>(DeedType, prismaEntity, { strategy: "excludeAll" });
|
||||
const DeedTypes = DeedType.hydrateArray<DeedType>(DeedType, deedTypeEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, DeedTypes);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -51,17 +51,17 @@ export default class DeedTypesController extends ApiController {
|
||||
await validateOrReject(deedTypeEntity, { groups: ["createDeedType"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityCreated = await this.deedTypesService.create(deedTypeEntity);
|
||||
const deedTypeEntityCreated = await this.deedTypesService.create(deedTypeEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deedTypeEntityCreated = DeedType.hydrate<DeedType>(prismaEntityCreated, {
|
||||
const deedType = DeedType.hydrate<DeedType>(deedTypeEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deedTypeEntityCreated);
|
||||
this.httpCreated(response, deedType);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -75,8 +75,17 @@ export default class DeedTypesController extends ApiController {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
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);
|
||||
|
||||
@ -84,17 +93,17 @@ export default class DeedTypesController extends ApiController {
|
||||
await validateOrReject(deedTypeEntity, { groups: ["updateDeedType"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityUpdated = await this.deedTypesService.update(uid, deedTypeEntity);
|
||||
const deedTypeEntityUpdated = await this.deedTypesService.update(uid, deedTypeEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deedTypeEntityUpdated = DeedType.hydrate<DeedType>(prismaEntityUpdated, {
|
||||
const deedType = DeedType.hydrate<DeedType>(deedTypeEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deedTypeEntityUpdated);
|
||||
this.httpSuccess(response, deedType);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -108,10 +117,11 @@ export default class DeedTypesController extends ApiController {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
let deedTypeEntity: DeedTypes;
|
||||
let deedTypeEntity: DeedTypes | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
@ -121,13 +131,18 @@ export default class DeedTypesController extends ApiController {
|
||||
deedTypeEntity = await this.deedTypesService.getByUid(uid);
|
||||
}
|
||||
|
||||
if (!deedTypeEntity) {
|
||||
this.httpNotFoundRequest(response, "deed type not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deedType = DeedType.hydrate<DeedType>(deedTypeEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deedType);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -24,15 +24,15 @@ export default class DeedsController extends ApiController {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
//call service to get prisma entity
|
||||
const prismaEntity: Deeds[] = await this.deedsService.get(query);
|
||||
const deedEntities: Deeds[] = await this.deedsService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deeds = Deed.map<Deed>(Deed, prismaEntity, { strategy: "excludeAll" });
|
||||
const deeds = Deed.hydrateArray<Deed>(Deed, deedEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deeds);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -46,10 +46,11 @@ export default class DeedsController extends ApiController {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
let deedEntity: Deeds;
|
||||
let deedEntity: Deeds | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
@ -59,13 +60,18 @@ export default class DeedsController extends ApiController {
|
||||
deedEntity = await this.deedsService.getByUid(uid);
|
||||
}
|
||||
|
||||
if (!deedEntity) {
|
||||
this.httpNotFoundRequest(response, "deed not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deed = Deed.hydrate<Deed>(deedEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deed);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -78,8 +84,17 @@ export default class DeedsController extends ApiController {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
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);
|
||||
|
||||
@ -87,17 +102,17 @@ export default class DeedsController extends ApiController {
|
||||
await validateOrReject(deedEntity, { groups: ["updateDeed"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityUpdated = await this.deedsService.update(uid, deedEntity);
|
||||
const deedEntityUpdated = await this.deedsService.update(uid, deedEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deedEntityUpdated = Deed.hydrate<Deed>(prismaEntityUpdated, {
|
||||
const deed = Deed.hydrate<Deed>(deedEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deedEntityUpdated);
|
||||
this.httpSuccess(response, deed);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -25,17 +25,17 @@ export default class DocumentTypesController extends ApiController {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntity: DocumentTypes[] = await this.documentTypesService.get(query);
|
||||
const documentTypeEntities: DocumentTypes[] = await this.documentTypesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const documentTypes = DocumentType.map<DocumentType>(DocumentType, prismaEntity, {
|
||||
const documentTypes = DocumentType.hydrateArray<DocumentType>(DocumentType, documentTypeEntities, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, documentTypes);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -51,15 +51,15 @@ export default class DocumentTypesController extends ApiController {
|
||||
//validate user
|
||||
await validateOrReject(documentTypeEntity, { groups: ["createDocumentType"], forbidUnknownValues: false });
|
||||
//call service to get prisma entity
|
||||
const prismaEntityCreated = await this.documentTypesService.create(documentTypeEntity);
|
||||
const documentTypeEntityCreated = await this.documentTypesService.create(documentTypeEntity);
|
||||
//Hydrate ressource with prisma entity
|
||||
const userEntityCreated = DocumentType.hydrate<DocumentType>(prismaEntityCreated, {
|
||||
const userEntityCreated = DocumentType.hydrate<DocumentType>(documentTypeEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
//success
|
||||
this.httpSuccess(response, userEntityCreated);
|
||||
this.httpCreated(response, userEntityCreated);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -72,7 +72,15 @@ export default class DocumentTypesController extends ApiController {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
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);
|
||||
@ -81,17 +89,17 @@ export default class DocumentTypesController extends ApiController {
|
||||
await validateOrReject(documentTypeEntity, { groups: ["update"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityUpdated = await this.documentTypesService.update(uid, documentTypeEntity);
|
||||
const documentTypeEntityUpdated = await this.documentTypesService.update(uid, documentTypeEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const documentTypeEntityUpdated = DocumentType.hydrate<DocumentType>(prismaEntityUpdated, {
|
||||
const documentType = DocumentType.hydrate<DocumentType>(documentTypeEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, documentTypeEntityUpdated);
|
||||
this.httpSuccess(response, documentType);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -104,10 +112,11 @@ export default class DocumentTypesController extends ApiController {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
let documentTypeEntity: DocumentTypes;
|
||||
let documentTypeEntity: DocumentTypes | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
@ -117,13 +126,18 @@ export default class DocumentTypesController extends ApiController {
|
||||
documentTypeEntity = await this.documentTypesService.getByUid(uid);
|
||||
}
|
||||
|
||||
if (!documentTypeEntity) {
|
||||
this.httpNotFoundRequest(response, "document not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const user = ObjectHydrate.hydrate<DocumentType>(new DocumentType(), documentTypeEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, user);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -25,15 +25,15 @@ export default class DocumentsController extends ApiController {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntity: Documents[] = await this.documentsService.get(query);
|
||||
const documentEntities: Documents[] = await this.documentsService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const documents = Document.map<Document>(Document, prismaEntity, { strategy: "excludeAll" });
|
||||
const documents = Document.hydrateArray<Document>(Document, documentEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, documents);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -52,17 +52,17 @@ export default class DocumentsController extends ApiController {
|
||||
await validateOrReject(documentEntity, { groups: ["createDocument"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityCreated = await this.documentsService.create(documentEntity);
|
||||
const documentEntityCreated = await this.documentsService.create(documentEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const documentEntityCreated = Document.hydrate<Document>(prismaEntityCreated, {
|
||||
const document = Document.hydrate<Document>(documentEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, documentEntityCreated);
|
||||
this.httpCreated(response, document);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -75,7 +75,15 @@ export default class DocumentsController extends ApiController {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
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
|
||||
@ -85,15 +93,15 @@ export default class DocumentsController extends ApiController {
|
||||
await validateOrReject(documentEntity, { groups: ["updateDocument"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity, req.body.refused_reason);
|
||||
const documentEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity, req.body.refused_reason);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const document = Document.hydrate<Document>(prismaEntityUpdated, { strategy: "excludeAll" });
|
||||
const document = Document.hydrate<Document>(documentEntityUpdated, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, document);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -106,7 +114,15 @@ export default class DocumentsController extends ApiController {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const documentFound = await this.documentsService.getByUid(uid);
|
||||
|
||||
if (!documentFound) {
|
||||
this.httpNotFoundRequest(response, "document not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
@ -118,7 +134,7 @@ export default class DocumentsController extends ApiController {
|
||||
//success
|
||||
this.httpSuccess(response, document);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -131,10 +147,11 @@ export default class DocumentsController extends ApiController {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
let documentEntity: Documents;
|
||||
let documentEntity: Documents | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
@ -144,13 +161,18 @@ export default class DocumentsController extends ApiController {
|
||||
documentEntity = await this.documentsService.getByUid(uid);
|
||||
}
|
||||
|
||||
if (!documentEntity) {
|
||||
this.httpNotFoundRequest(response, "document not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const document = Document.hydrate<Document>(documentEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, document);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import FilesService from "@Services/private-services/FilesService/FilesService";
|
||||
import { Files } from "@prisma/client";
|
||||
import { File, Document } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { File } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService";
|
||||
|
||||
@ -26,10 +26,10 @@ export default class FilesController extends ApiController {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntity = await this.filesService.get(query);
|
||||
const fileEntities = await this.filesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const files = File.map<File>(File, prismaEntity, { strategy: "excludeAll" });
|
||||
const files = File.hydrateArray<File>(File, fileEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, files);
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -85,19 +85,25 @@ export default class FilesController extends ApiController {
|
||||
await validateOrReject(fileEntity, { groups: ["createFile"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityCreated = await this.filesService.create(fileEntity, req.file);
|
||||
const fileEntityCreated = await this.filesService.create(fileEntity, req.file);
|
||||
|
||||
const document = await this.documentService.getByUid(fileEntity.document!.uid!);
|
||||
|
||||
if(!document){
|
||||
this.httpNotFoundRequest(response, "document not found");
|
||||
return;
|
||||
}
|
||||
|
||||
const document: Document = await this.documentService.getByUid(fileEntity.document!.uid!);
|
||||
document.document_status = "DEPOSITED";
|
||||
await this.documentService.update(document.uid!, document);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const fileEntityCreated = File.hydrate<File>(prismaEntityCreated, {
|
||||
const fileEntityHydrated = File.hydrate<File>(fileEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, fileEntityCreated);
|
||||
this.httpCreated(response, fileEntityHydrated);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
return;
|
||||
@ -115,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);
|
||||
|
||||
@ -122,10 +135,10 @@ export default class FilesController extends ApiController {
|
||||
await validateOrReject(fileEntity, { groups: ["updateFile"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityUpdated: Files = await this.filesService.update(uid, fileEntity);
|
||||
const fileEntityUpdated: Files = await this.filesService.update(uid, fileEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const file = File.hydrate<File>(prismaEntityUpdated, { strategy: "excludeAll" });
|
||||
const file = File.hydrate<File>(fileEntityUpdated, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, file);
|
||||
@ -147,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);
|
||||
|
||||
@ -154,6 +174,7 @@ export default class FilesController extends ApiController {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const file = File.hydrate<File>(fileEntity, { strategy: "excludeAll" });
|
||||
|
||||
|
@ -23,15 +23,15 @@ export default class OfficeFoldersController extends ApiController {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
//call service to get prisma entity
|
||||
const prismaEntity: OfficeFolders[] = await this.officeFoldersService.get(query);
|
||||
const officeFolderEntities: OfficeFolders[] = await this.officeFoldersService.get(query);
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeFolders = OfficeFolder.map<OfficeFolder>(OfficeFolder, prismaEntity, {
|
||||
const officeFolders = OfficeFolder.hydrateArray<OfficeFolder>(OfficeFolder, officeFolderEntities, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
//success
|
||||
this.httpSuccess(response, officeFolders);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -48,15 +48,15 @@ export default class OfficeFoldersController extends ApiController {
|
||||
//validate folder
|
||||
await validateOrReject(officeFolderEntity, { groups: ["createFolder"] , forbidUnknownValues: false });
|
||||
//call service to get prisma entity
|
||||
const prismaEntityCreated = await this.officeFoldersService.create(officeFolderEntity);
|
||||
const officeFolderEntityCreated = await this.officeFoldersService.create(officeFolderEntity);
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeFolderEntityCreated = OfficeFolder.hydrate<OfficeFolder>(prismaEntityCreated, {
|
||||
const officeFolders = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
//success
|
||||
this.httpSuccess(response, officeFolderEntityCreated);
|
||||
this.httpCreated(response, officeFolders);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -69,8 +69,17 @@ export default class OfficeFoldersController extends ApiController {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
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);
|
||||
|
||||
@ -78,17 +87,17 @@ export default class OfficeFoldersController extends ApiController {
|
||||
await validateOrReject(officeFolderEntity, { groups: ["updateFolder"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityUpdated = await this.officeFoldersService.update(uid, officeFolderEntity);
|
||||
const officeFolderEntityUpdated = await this.officeFoldersService.update(uid, officeFolderEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeFolderEntityUpdated = OfficeFolder.hydrate<OfficeFolder>(prismaEntityUpdated, {
|
||||
const officeFolders = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeFolderEntityUpdated);
|
||||
this.httpSuccess(response, officeFolders);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -102,10 +111,11 @@ export default class OfficeFoldersController extends ApiController {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
let officeFolderEntity: OfficeFolders;
|
||||
let officeFolderEntity: OfficeFolders | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
@ -115,13 +125,18 @@ export default class OfficeFoldersController extends ApiController {
|
||||
officeFolderEntity = await this.officeFoldersService.getByUid(uid);
|
||||
}
|
||||
|
||||
if (!officeFolderEntity) {
|
||||
this.httpNotFoundRequest(response, "folder not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeFolder);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
this.httpSuccess(response, await this.officeFoldersService.getByUid("uid"));
|
||||
@ -135,7 +150,15 @@ export default class OfficeFoldersController extends ApiController {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const officeFolderFound = await this.officeFoldersService.getByUid(uid);
|
||||
|
||||
if (!officeFolderFound) {
|
||||
this.httpNotFoundRequest(response, "office folder not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
@ -147,7 +170,7 @@ export default class OfficeFoldersController extends ApiController {
|
||||
//success
|
||||
this.httpSuccess(response, officeFolder);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -22,13 +22,13 @@ export default class OfficesController extends ApiController {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
//call service to get prisma entity
|
||||
const officesEntity: Offices[] = await this.officesService.get(query);
|
||||
const officesEntities: Offices[] = await this.officesService.get(query);
|
||||
//Hydrate ressource with prisma entity
|
||||
const offices = OfficeResource.map<OfficeResource>(OfficeResource, officesEntity, { strategy: "excludeAll" });
|
||||
const offices = OfficeResource.hydrateArray<OfficeResource>(OfficeResource, officesEntities, { strategy: "excludeAll" });
|
||||
//success
|
||||
this.httpSuccess(response, offices);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -43,15 +43,15 @@ export default class OfficesController extends ApiController {
|
||||
//validate user
|
||||
await validateOrReject(officeEntity, { groups: ["createOffice"], forbidUnknownValues: false });
|
||||
//call service to get prisma entity
|
||||
const prismaEntityCreated = await this.officesService.create(officeEntity);
|
||||
const officeEntityCreated = await this.officesService.create(officeEntity);
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeEntityCreated = OfficeResource.hydrate<OfficeResource>(prismaEntityCreated, {
|
||||
const office = OfficeResource.hydrate<OfficeResource>(officeEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
//success
|
||||
this.httpSuccess(response, officeEntityCreated);
|
||||
this.httpCreated(response, office);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -63,22 +63,30 @@ export default class OfficesController extends ApiController {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
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
|
||||
await validateOrReject(officeEntity, { groups: ["update"] });
|
||||
//call service to get prisma entity
|
||||
const prismaEntityUpdated = await this.officesService.update(uid, officeEntity);
|
||||
const officeEntityUpdated = await this.officesService.update(uid, officeEntity);
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeEntityUpdated = OfficeResource.hydrate<OfficeResource>(prismaEntityUpdated, {
|
||||
const office = OfficeResource.hydrate<OfficeResource>(officeEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
//success
|
||||
this.httpSuccess(response, officeEntityUpdated);
|
||||
this.httpSuccess(response, office);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -90,9 +98,10 @@ export default class OfficesController extends ApiController {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
let officeEntity: Offices;
|
||||
let officeEntity: Offices | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
@ -101,12 +110,18 @@ export default class OfficesController extends ApiController {
|
||||
//call service to get prisma entity
|
||||
officeEntity = await this.officesService.getByUid(uid);
|
||||
}
|
||||
|
||||
if (!officeEntity) {
|
||||
this.httpNotFoundRequest(response, "office not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const office = OfficeResource.hydrate<OfficeResource>(officeEntity, { strategy: "excludeAll" });
|
||||
//success
|
||||
this.httpSuccess(response, office);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -24,15 +24,15 @@ export default class UsersController extends ApiController {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
|
||||
//call service to get prisma entity
|
||||
const usersEntity = await this.usersService.get(query);
|
||||
const usersEntities = await this.usersService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const users = User.map<User>(User, usersEntity, { strategy: "excludeAll" });
|
||||
const users = User.hydrateArray<User>(User, usersEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, users);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -50,17 +50,17 @@ export default class UsersController extends ApiController {
|
||||
await validateOrReject(userEntity, { groups: ["createUser"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityCreated = await this.usersService.create(userEntity);
|
||||
const userEntityCreated = await this.usersService.create(userEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const userEntityCreated = User.hydrate<User>(prismaEntityCreated, {
|
||||
const user = User.hydrate<User>(userEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, userEntityCreated);
|
||||
this.httpCreated(response, user);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -73,8 +73,17 @@ export default class UsersController extends ApiController {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
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);
|
||||
|
||||
@ -82,17 +91,17 @@ export default class UsersController extends ApiController {
|
||||
await validateOrReject(userEntity, { groups: ["update"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityUpdated = await this.usersService.update(uid, userEntity);
|
||||
const userEntityUpdated = await this.usersService.update(uid, userEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const userEntityUpdated = User.hydrate<User>(prismaEntityUpdated, {
|
||||
const user = User.hydrate<User>(userEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, userEntityUpdated);
|
||||
this.httpSuccess(response, user);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -105,9 +114,10 @@ export default class UsersController extends ApiController {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
let userEntity: Users;
|
||||
let userEntity: Users | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
@ -117,13 +127,18 @@ export default class UsersController extends ApiController {
|
||||
userEntity = await this.usersService.getByUid(uid);
|
||||
}
|
||||
|
||||
if (!userEntity) {
|
||||
this.httpNotFoundRequest(response, "user not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const user = User.hydrate<User>(userEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, user);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -26,17 +26,13 @@ export default class AddressesRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find one address
|
||||
*/
|
||||
public async findOneByUid(uid: string): Promise<Addresses> {
|
||||
public async findOneByUid(uid: string): Promise<Addresses | null> {
|
||||
const addressEntity = await this.model.findUnique({
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
});
|
||||
|
||||
if (!addressEntity) {
|
||||
throw new Error("Address not found");
|
||||
}
|
||||
|
||||
return addressEntity;
|
||||
}
|
||||
}
|
||||
|
@ -26,17 +26,13 @@ export default class ContactsRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find unique contact
|
||||
*/
|
||||
public async findOneByUid(uid: string): Promise<Contacts> {
|
||||
public async findOneByUid(uid: string): Promise<Contacts | null> {
|
||||
const contactEntity = await this.model.findUnique({
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
});
|
||||
|
||||
if (!contactEntity) {
|
||||
throw new Error("contact not found");
|
||||
}
|
||||
|
||||
return contactEntity;
|
||||
}
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ export default class CustomersRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find unique customer
|
||||
*/
|
||||
public async findOneByUid(uid: string, query?: any): Promise<Customers> {
|
||||
public async findOneByUid(uid: string, query?: any): Promise<Customers | null> {
|
||||
const findOneArgs: Prisma.CustomersFindUniqueArgs = {
|
||||
where: {
|
||||
uid: uid,
|
||||
@ -108,9 +108,6 @@ export default class CustomersRepository extends BaseRepository {
|
||||
findOneArgs.include = query;
|
||||
}
|
||||
const customerEntity = await this.model.findUnique(findOneArgs);
|
||||
if (!customerEntity) {
|
||||
throw new Error("Customer not found");
|
||||
}
|
||||
|
||||
return customerEntity;
|
||||
}
|
||||
|
@ -26,17 +26,13 @@ export default class DeedTypeHasDocumentTypesRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find unique relation between deed type and a document type
|
||||
*/
|
||||
public async findOneByUid(uid: string): Promise<DeedTypeHasDocumentTypes> {
|
||||
public async findOneByUid(uid: string): Promise<DeedTypeHasDocumentTypes | null> {
|
||||
const deedTypeHasDoculmentTypesEntity = await this.model.findUnique({
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
});
|
||||
|
||||
if (!deedTypeHasDoculmentTypesEntity) {
|
||||
throw new Error("deed type not found");
|
||||
}
|
||||
|
||||
return deedTypeHasDoculmentTypesEntity;
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ export default class DeedTypesRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find unique deed type
|
||||
*/
|
||||
public async findOneByUid(uid: string, query?: any): Promise<DeedTypes> {
|
||||
public async findOneByUid(uid: string, query?: any): Promise<DeedTypes | null> {
|
||||
const findOneArgs: Prisma.DeedTypesFindUniqueArgs = {
|
||||
where: {
|
||||
uid: uid,
|
||||
@ -102,10 +102,6 @@ export default class DeedTypesRepository extends BaseRepository {
|
||||
}
|
||||
const deedTypeEntity = await this.model.findUnique(findOneArgs);
|
||||
|
||||
if (!deedTypeEntity) {
|
||||
throw new Error("deed type not found");
|
||||
}
|
||||
|
||||
return deedTypeEntity;
|
||||
}
|
||||
}
|
||||
|
@ -26,17 +26,13 @@ export default class DeedHasDocumentTypesRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find unique relation between deed and a document type
|
||||
*/
|
||||
public async findOneByUid(uid: string): Promise<DeedHasDocumentTypes> {
|
||||
public async findOneByUid(uid: string): Promise<DeedHasDocumentTypes | null> {
|
||||
const deedHasDocumentTypesEntity = await this.model.findUnique({
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
});
|
||||
|
||||
if (!deedHasDocumentTypesEntity) {
|
||||
throw new Error("relation between deed and document type not found");
|
||||
}
|
||||
|
||||
return deedHasDocumentTypesEntity;
|
||||
}
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ export default class DeedsRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find unique deed
|
||||
*/
|
||||
public async findOneByUid(uid: string, query?: any): Promise<Deeds> {
|
||||
public async findOneByUid(uid: string, query?: any): Promise<Deeds | null> {
|
||||
const findOneArgs: Prisma.DeedsFindUniqueArgs = {
|
||||
where: {
|
||||
uid: uid,
|
||||
@ -101,10 +101,6 @@ export default class DeedsRepository extends BaseRepository {
|
||||
}
|
||||
const deedTypeEntity = await this.model.findUnique(findOneArgs);
|
||||
|
||||
if (!deedTypeEntity) {
|
||||
throw new Error("deed not found");
|
||||
}
|
||||
|
||||
return deedTypeEntity;
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ export default class DocumentTypesRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : find unique document type
|
||||
*/
|
||||
public async findOneByUid(uid: string, query?: any): Promise<DocumentTypes> {
|
||||
public async findOneByUid(uid: string, query?: any): Promise<DocumentTypes | null> {
|
||||
const findOneArgs: Prisma.DocumentTypesFindUniqueArgs = {
|
||||
where: {
|
||||
uid: uid,
|
||||
@ -78,10 +78,6 @@ export default class DocumentTypesRepository extends BaseRepository {
|
||||
}
|
||||
const documentTypeEntity = await this.model.findUnique(findOneArgs);
|
||||
|
||||
if (!documentTypeEntity) {
|
||||
throw new Error("Document Type not found");
|
||||
}
|
||||
|
||||
return documentTypeEntity;
|
||||
}
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ export default class DocumentsRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find unique document
|
||||
*/
|
||||
public async findOneByUid(uid: string, query?: any): Promise<Documents> {
|
||||
public async findOneByUid(uid: string, query?: any): Promise<Documents | null> {
|
||||
const findOneArgs: Prisma.DocumentsFindUniqueArgs = {
|
||||
where: {
|
||||
uid: uid,
|
||||
@ -119,9 +119,6 @@ export default class DocumentsRepository extends BaseRepository {
|
||||
findOneArgs.include = query;
|
||||
}
|
||||
const documentEntity = await this.model.findUnique(findOneArgs);
|
||||
if (!documentEntity) {
|
||||
throw new Error("Document not found");
|
||||
}
|
||||
|
||||
return documentEntity;
|
||||
}
|
||||
|
@ -81,6 +81,7 @@ export default class FilesRepository extends BaseRepository {
|
||||
uid: uid,
|
||||
},
|
||||
});
|
||||
|
||||
return fileEntity;
|
||||
}
|
||||
}
|
||||
|
@ -26,17 +26,13 @@ export default class OfficeFoldersHasCustomerRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find a unique relation between an office folder and customers
|
||||
*/
|
||||
public async findOneByUid(uid: string): Promise<OfficeFolderHasCustomers> {
|
||||
public async findOneByUid(uid: string): Promise<OfficeFolderHasCustomers | null> {
|
||||
const officeFolderHasCustomersEntity = await this.model.findUnique({
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
});
|
||||
|
||||
if (!officeFolderHasCustomersEntity) {
|
||||
throw new Error("relation between office folder and customer not found");
|
||||
}
|
||||
|
||||
return officeFolderHasCustomersEntity;
|
||||
}
|
||||
}
|
||||
|
@ -26,17 +26,13 @@ export default class OfficeFoldersHasStakeholderRepository extends BaseRepositor
|
||||
/**
|
||||
* @description : Find a unique relation between an office folder and stakeholders
|
||||
*/
|
||||
public async findOneByUid(uid: string): Promise<OfficeFolderHasStakeholders> {
|
||||
public async findOneByUid(uid: string): Promise<OfficeFolderHasStakeholders | null> {
|
||||
const officeFolderHasStakeholdersEntity = await this.model.findUnique({
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
});
|
||||
|
||||
if (!officeFolderHasStakeholdersEntity) {
|
||||
throw new Error("relation between office folder and stakeholder not found");
|
||||
}
|
||||
|
||||
return officeFolderHasStakeholdersEntity;
|
||||
}
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ export default class OfficeFoldersRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find one office folder
|
||||
*/
|
||||
public async findOneByUid(uid: string, query?: any): Promise<OfficeFolders> {
|
||||
public async findOneByUid(uid: string, query?: any): Promise<OfficeFolders | null> {
|
||||
const findOneArgs: Prisma.OfficeFoldersFindUniqueArgs = {
|
||||
where: {
|
||||
uid: uid,
|
||||
@ -133,10 +133,6 @@ export default class OfficeFoldersRepository extends BaseRepository {
|
||||
}
|
||||
const officeFolderEntity = await this.model.findUnique(findOneArgs);
|
||||
|
||||
if (!officeFolderEntity) {
|
||||
throw new Error("office folder not found");
|
||||
}
|
||||
|
||||
return officeFolderEntity;
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ export default class OfficesRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find one office
|
||||
*/
|
||||
public async findOneByUid(uid: string, query?: any): Promise<Offices> {
|
||||
public async findOneByUid(uid: string, query?: any): Promise<Offices | null> {
|
||||
const findOneArgs: Prisma.OfficesFindUniqueArgs = {
|
||||
where: {
|
||||
uid: uid,
|
||||
@ -82,10 +82,6 @@ export default class OfficesRepository extends BaseRepository {
|
||||
}
|
||||
const officeEntity = await this.model.findUnique(findOneArgs);
|
||||
|
||||
if (!officeEntity) {
|
||||
throw new Error("office not found");
|
||||
}
|
||||
|
||||
return officeEntity;
|
||||
}
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ export default class UsersRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find one user
|
||||
*/
|
||||
public async findOneByUid(uid: string, query?: any): Promise<Users> {
|
||||
public async findOneByUid(uid: string, query?: any): Promise<Users | null> {
|
||||
const findOneArgs: Prisma.UsersFindUniqueArgs = {
|
||||
where: {
|
||||
uid: uid,
|
||||
@ -149,10 +149,6 @@ export default class UsersRepository extends BaseRepository {
|
||||
}
|
||||
const userEntity = await this.model.findUnique(findOneArgs);
|
||||
|
||||
if (!userEntity) {
|
||||
throw new Error("User not found");
|
||||
}
|
||||
|
||||
return userEntity;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ export default class DocumentsService extends BaseService {
|
||||
* @description : Get all documents
|
||||
* @throws {Error} If documents cannot be get
|
||||
*/
|
||||
public async get(query: any) {
|
||||
public async get(query: any): Promise<Documents[]> {
|
||||
return this.documentsRepository.findMany(query);
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ export default class DocumentsService extends BaseService {
|
||||
* @description : Get a document by uid
|
||||
* @throws {Error} If document cannot be get by uid
|
||||
*/
|
||||
public async getByUid(uid: string, query?: any) {
|
||||
public async getByUid(uid: string, query?: any): Promise<Documents | null> {
|
||||
return this.documentsRepository.findOneByUid(uid, query);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import AddressesRepository from "@Repositories/AddressesRepository";
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { Addresses } from "@prisma/client";
|
||||
import { Service } from "typedi";
|
||||
|
||||
@Service()
|
||||
@ -12,7 +13,7 @@ export default class AddressesService extends BaseService {
|
||||
* @description : Get all addresses
|
||||
* @throws {Error} If addresses cannot be get
|
||||
*/
|
||||
public async get(query: any) {
|
||||
public async get(query: any): Promise<Addresses[]> {
|
||||
return this.addressRepository.findMany(query);
|
||||
}
|
||||
|
||||
@ -20,7 +21,7 @@ export default class AddressesService extends BaseService {
|
||||
* @description : Get a address by uid
|
||||
* @throws {Error} If address cannot be get
|
||||
*/
|
||||
public async getByUid(uid: string) {
|
||||
public async getByUid(uid: string): Promise<Addresses | null> {
|
||||
return this.addressRepository.findOneByUid(uid);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import ContactsRepository from "@Repositories/ContactsRepository";
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { Contacts } from "@prisma/client";
|
||||
import { Service } from "typedi";
|
||||
|
||||
@Service()
|
||||
@ -12,7 +13,7 @@ export default class ContactsService extends BaseService {
|
||||
* @description : Get all contacts
|
||||
* @throws {Error} If contacts cannot be get
|
||||
*/
|
||||
public async get(query: any) {
|
||||
public async get(query: any): Promise<Contacts[]> {
|
||||
return this.contactRepository.findMany(query);
|
||||
}
|
||||
|
||||
@ -20,7 +21,7 @@ export default class ContactsService extends BaseService {
|
||||
* @description : Get a contact by uid
|
||||
* @throws {Error} If contact cannot be get
|
||||
*/
|
||||
public async getByUid(uid: string) {
|
||||
public async getByUid(uid: string): Promise<Contacts | null> {
|
||||
return this.contactRepository.findOneByUid(uid);
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import IpfsService from "../IpfsService/IpfsService";
|
||||
import { BackendVariables } from "@Common/config/variables/Variables";
|
||||
import { Readable } from "stream";
|
||||
import { v4 } from "uuid";
|
||||
import { Files } from "@prisma/client";
|
||||
|
||||
@Service()
|
||||
export default class FilesService extends BaseService {
|
||||
@ -23,7 +24,7 @@ export default class FilesService extends BaseService {
|
||||
* @description : Get all files
|
||||
* @throws {Error} If files cannot be ge
|
||||
*/
|
||||
public async get(query: any) {
|
||||
public async get(query: any): Promise<Files[]> {
|
||||
return this.filesRepository.findMany(query);
|
||||
}
|
||||
|
||||
@ -31,7 +32,7 @@ export default class FilesService extends BaseService {
|
||||
* @description : Get a file by uid
|
||||
* @throws {Error} If project cannot be created
|
||||
*/
|
||||
public async getByUid(uid: string) {
|
||||
public async getByUid(uid: string): Promise<Files | null> {
|
||||
return this.filesRepository.findOneByUid(uid);
|
||||
}
|
||||
|
||||
@ -41,6 +42,7 @@ export default class FilesService extends BaseService {
|
||||
*/
|
||||
public async download(uid: string) {
|
||||
const file = await this.filesRepository.findOneByUid(uid);
|
||||
console.log(file, uid);
|
||||
if (!file?.key) return null;
|
||||
const fileResult = await fetch(file.file_path);
|
||||
const fileContent = await fileResult.arrayBuffer();
|
||||
@ -51,7 +53,7 @@ export default class FilesService extends BaseService {
|
||||
* @description : Create a new file
|
||||
* @throws {Error} If file cannot be created
|
||||
*/
|
||||
public async create(file: File, fileData: Express.Multer.File) {
|
||||
public async create(file: File, fileData: Express.Multer.File): Promise<Files> {
|
||||
const key = v4();
|
||||
fileData.mimetype;
|
||||
fileData.size;
|
||||
@ -67,7 +69,7 @@ export default class FilesService extends BaseService {
|
||||
* @description : Modify a new file
|
||||
* @throws {Error} If file cannot be modified
|
||||
*/
|
||||
public async update(uid: string, file: File) {
|
||||
public async update(uid: string, file: File): Promise<Files> {
|
||||
return this.filesRepository.update(uid, file);
|
||||
}
|
||||
|
||||
@ -75,10 +77,10 @@ export default class FilesService extends BaseService {
|
||||
* @description : Delete a file key and archive
|
||||
* @throws {Error} If file key cannot be deleted or archived
|
||||
*/
|
||||
public async deleteKeyAndArchive(uid: string) {
|
||||
public async deleteKeyAndArchive(uid: string): Promise<Files> {
|
||||
try {
|
||||
const fileToUnpin = await this.filesRepository.findOneByUid(uid);
|
||||
if(!fileToUnpin) return null;
|
||||
if(!fileToUnpin) throw new Error("file not found");
|
||||
const fileHash = fileToUnpin.file_path.substring(this.variables.PINATA_GATEWAY.length);
|
||||
await this.ipfsService.unpinFile(fileHash);
|
||||
} catch(error) {
|
||||
|
@ -38,7 +38,7 @@ export default class CustomersService extends BaseService {
|
||||
* @description : Get a customer by uid
|
||||
* @throws {Error} If customer cannot be get by uid
|
||||
*/
|
||||
public async getByUid(uid: string, query?: any): Promise<Customers> {
|
||||
public async getByUid(uid: string, query?: any): Promise<Customers | null> {
|
||||
return this.customerRepository.findOneByUid(uid, query);
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ export default class DeedTypesService extends BaseService {
|
||||
* @description : Get a deedtype by uid
|
||||
* @throws {Error} If deed-type cannot be get by uid
|
||||
*/
|
||||
public async getByUid(uid: string, query?: any) {
|
||||
public async getByUid(uid: string, query?: any): Promise<DeedTypes | null> {
|
||||
return this.deedTypeRepository.findOneByUid(uid, query);
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ export default class DeedsService extends BaseService {
|
||||
* @description : Get a deed by uid
|
||||
* @throws {Error} If deed-type cannot be get by uid
|
||||
*/
|
||||
public async getByUid(uid: string, query?: any) {
|
||||
public async getByUid(uid: string, query?: any): Promise<Deeds | null> {
|
||||
return this.deedRepository.findOneByUid(uid, query);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ export default class DocumentTypesService extends BaseService {
|
||||
* @description : Get all document-types
|
||||
* @throws {Error} If document-types cannot be get
|
||||
*/
|
||||
public async get(query: any) {
|
||||
public async get(query: any): Promise<DocumentTypes[]> {
|
||||
return this.documentTypeRepository.findMany(query);
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ export default class DocumentTypesService extends BaseService {
|
||||
* @description : Get a document-type by uid
|
||||
* @throws {Error} If document-type is not found
|
||||
*/
|
||||
public async getByUid(uid: string, query?: any) {
|
||||
public async getByUid(uid: string, query?: any): Promise<DocumentTypes | null> {
|
||||
return this.documentTypeRepository.findOneByUid(uid, query);
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ export default class DocumentsService extends BaseService {
|
||||
*/
|
||||
public async delete(uid: string): Promise<Documents> {
|
||||
const documentEntity = await this.documentsRepository.findOneByUid(uid, { files: true });
|
||||
|
||||
if(!documentEntity) throw new Error("document not found");
|
||||
const document = Document.hydrate<Document>(documentEntity, { strategy: "excludeAll" });
|
||||
|
||||
if (document.files && document.files.length !== 0) {
|
||||
@ -61,7 +61,7 @@ export default class DocumentsService extends BaseService {
|
||||
* @description : Get a document by uid
|
||||
* @throws {Error} If document cannot be get by uid
|
||||
*/
|
||||
public async getByUid(uid: string, query?: any) {
|
||||
public async getByUid(uid: string, query?: any): Promise<Documents | null> {
|
||||
return this.documentsRepository.findOneByUid(uid, query);
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ export default class OfficeFoldersService extends BaseService {
|
||||
* @description : Get all folders
|
||||
* @throws {Error} If folders cannot be get
|
||||
*/
|
||||
public async get(query: any) {
|
||||
public async get(query: any): Promise<OfficeFolders[]> {
|
||||
return this.officeFoldersRepository.findMany(query);
|
||||
}
|
||||
|
||||
@ -31,6 +31,7 @@ export default class OfficeFoldersService extends BaseService {
|
||||
*/
|
||||
public async create(officeFolderEntity: OfficeFolder): Promise<OfficeFolders> {
|
||||
const deedType = await this.deedTypeService.getByUid(officeFolderEntity.deed!.deed_type!.uid!);
|
||||
if(!deedType) throw new Error('deed type not found');
|
||||
if(deedType.archived_at) throw new Error('deed type is archived');
|
||||
const deed = await this.deedRepository.create(officeFolderEntity.deed!);
|
||||
officeFolderEntity.deed!.uid = deed.uid;
|
||||
@ -49,7 +50,7 @@ export default class OfficeFoldersService extends BaseService {
|
||||
* @description : Get a folder by uid
|
||||
* @throws {Error} If folder cannot be get by uid
|
||||
*/
|
||||
public async getByUid(uid: string, query?: any) {
|
||||
public async getByUid(uid: string, query?: any): Promise<OfficeFolders | null> {
|
||||
return this.officeFoldersRepository.findOneByUid(uid, query);
|
||||
}
|
||||
|
||||
@ -59,6 +60,7 @@ export default class OfficeFoldersService extends BaseService {
|
||||
*/
|
||||
public async delete(uid: string): Promise<OfficeFolders> {
|
||||
const officeFolderEntity = await this.officeFoldersRepository.findOneByUid(uid, { office_folder_has_customers: true });
|
||||
if(!officeFolderEntity) throw new Error('office folder not found');
|
||||
const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntity, { strategy: "excludeAll" });
|
||||
|
||||
if (officeFolder.office_folder_has_customers && officeFolder.office_folder_has_customers.length !== 0) {
|
||||
|
@ -38,7 +38,7 @@ export default class OfficesService extends BaseService {
|
||||
* @description : Get a office by uid
|
||||
* @throws {Error} If office cannot be get
|
||||
*/
|
||||
public async getByUid(uid: string, query?: any): Promise<Offices> {
|
||||
public async getByUid(uid: string, query?: any): Promise<Offices | null> {
|
||||
return this.officeRepository.findOneByUid(uid, query);
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ export default class UsersService extends BaseService {
|
||||
* @description : Get a user by uid
|
||||
* @throws {Error} If user cannot be get by uid
|
||||
*/
|
||||
public getByUid(uid: string, query?: any): Promise<Users> {
|
||||
public getByUid(uid: string, query?: any): Promise<Users | null> {
|
||||
return this.userRepository.findOneByUid(uid, query);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user