Skip to content

Commit

Permalink
Fix error when updating tournament state
Browse files Browse the repository at this point in the history
  • Loading branch information
paolocattani committed Aug 7, 2020
1 parent 4b76388 commit ee3cc6e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion server/controller/tournament.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ router.put(
withAuth,
asyncMiddleware(async (req: AppRequest, res: Response, next: NextFunction) => {
const result = await update(req.user!, parseBody(req.body));
return res.sendStatus(result ? 200 : 500);
return res.status(200).json(result);
})
);

Expand Down
15 changes: 9 additions & 6 deletions server/manager/tournament.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,23 @@ export const listAll = async (user: UserDTO): Promise<TournamentDTO[]> => {
};

// Aggiorna un torneo esistente
export const update = async (user: UserDTO, model: TournamentDTO): Promise<boolean> => {
export const update = async (user: UserDTO, model: TournamentDTO): Promise<TournamentDTO | null> => {
logProcess(className + 'update', 'start');
try {
const params = new Map<string, WhereOptions | Object>();
params.set('id', model.id);
const t = await findByParams(params, user);
if (!t) return false;
else await t.update({ progress: model.progress });
if (!t) {
logProcess(className + 'update', 'end : Tournament not found');
return model;
}
const result = await t.update({ progress: model.progress });
logProcess(className + 'update', 'end');
return convertEntityToDTO(result);
} catch (error) {
logProcess(className + 'update', 'error');
return false;
return model;
}
logProcess(className + 'update', 'end');
return true;
};

// Cerca un torneo tramite ID
Expand Down

0 comments on commit ee3cc6e

Please sign in to comment.