Skip to content

Commit

Permalink
envolve try-catch instituion save
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasgehl3n committed Oct 5, 2023
1 parent b5b1f1d commit e202cb7
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/controllers/InstitutionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ const _mapRequestToData = async (req: Request) => {
(file: Express.Multer.File) =>
file.fieldname == 'logo'
);
if(!data.id) {

if (!data.id) {
const authenticatedRequest = req as unknown as AuthenticatedRequest;
data.idUserCreator = authenticatedRequest.user!.id;
}
Expand Down Expand Up @@ -135,19 +135,25 @@ const sortingOptions: SortingOptions = {

class InstitutionController {
public static async save(req: Request, res: Response) {
await _deletePublicImages(req, res);
const data = await _mapRequestToData(req);
const authenticatedRequest = req as unknown as AuthenticatedRequest;
const shouldGenerateUserService = !data.id;
try {
await _deletePublicImages(req, res);
const data = await _mapRequestToData(req);
const authenticatedRequest = req as unknown as AuthenticatedRequest;
const shouldGenerateUserService = !data.id;

await InstitutionService.SaveWithDependences(data);
await InstitutionService.SaveWithDependences(data);

if (shouldGenerateUserService) {
console.log(authenticatedRequest.user)
UserRoleService.GenerateUserServiceToInstitution(authenticatedRequest.user!, data);
}
if (shouldGenerateUserService) {
console.log(authenticatedRequest.user)
UserRoleService.GenerateUserServiceToInstitution(authenticatedRequest.user!, data);
}

return res.status(200).send({});
return res.status(200).send({});
}
catch (error) {
console.error(error);
return res.status(500).json(error).send();
}
}

public static async publicDetail(req: Request, res: Response) {
Expand All @@ -159,8 +165,8 @@ class InstitutionController {
],
attributes: {
exclude: [
'receive_volunteers',
'idAddress',
'receive_volunteers',
'idAddress',
'document',
'idUserCreator'
]
Expand Down

0 comments on commit e202cb7

Please sign in to comment.