Skip to content
Snippets Groups Projects
Commit 099068fb authored by Ivan Alglave's avatar Ivan Alglave
Browse files

fix: PUT not outputs and saves correctly the internship

parent 818ef0ba
No related branches found
No related tags found
1 merge request!5Crud internship
import { Injectable, NotFoundException } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { CONFLICT } from 'src/shared/HttpError';
import { BAD_REQUEST, CONFLICT, INTERNAL } from 'src/shared/HttpError';
import { STATE_STUDENT_ENTERS_INTERNSHIP_INFORMATION } from 'src/shared/InternshipState';
import { CreateInternshipDto } from '../dto/create-internship.dto';
import { InternshipDto } from '../dto/internship.dto';
......@@ -58,6 +58,7 @@ export class InternshipDao {
): Promise<Internship | void> =>
new Promise((resolve, reject) => {
// Check if information modification is allowed -> current state is information input by student and updating is allowed
if (studentId !== internship.studentId) reject(BAD_REQUEST);
const decoratedInternship = this.toInternshipDtoWithTracking(internship);
this._internshipModel.findOneAndReplace(
{
......@@ -71,7 +72,8 @@ export class InternshipDao {
},
(err, value) => {
if (err) reject(err.message);
resolve(value);
// if (typeof value !== typeof Internship) reject(INTERNAL);
resolve(value as Internship);
},
);
});
......@@ -90,7 +92,7 @@ export class InternshipDao {
return {
...createInternshipDto,
tracking: {
state: 'state-1',
state: STATE_STUDENT_ENTERS_INTERNSHIP_INFORMATION,
},
};
};
......
......@@ -3,10 +3,14 @@ import {
NotFoundException,
ConflictException,
UnprocessableEntityException,
BadRequestException,
InternalServerErrorException,
} from '@nestjs/common';
export const NOT_FOUND = new NotFoundException();
export const CONFLICT = new ConflictException();
export const BAD_REQUEST = new BadRequestException();
export const INTERNAL = new InternalServerErrorException();
export const BAD_TRACKING_STATE = (badState: string) =>
new UnprocessableEntityException(`Unknown state [${badState}]`);
export const CUSTOM = (reason: string, errorStatus: number) =>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment