Skip to content
Snippets Groups Projects
Unverified Commit d4bdf5cc authored by Nabilsenko's avatar Nabilsenko Committed by GitHub
Browse files

Merge branch 'master' into login

parents d936324f b64f7ddf
Branches
No related tags found
1 merge request!6feat: added login to people
Showing
with 440 additions and 3 deletions
export class CompensationEntity {
gratificationAmount: string;
modalities: string;
othersAdvantages: string;
constructor(partial: Partial<CompensationEntity>) {
Object.assign(this, partial);
}
}
import { AffectationEntity } from './affectation.entity';
import { CompanyEntity } from './company.entity';
import { CompensationEntity } from './compensation.entity';
import { StudentEntity } from './student.entity';
export class InformationEntity {
student: StudentEntity;
company: CompanyEntity;
affectation: AffectationEntity;
compensation: CompensationEntity;
internshipDescription: string;
constructor(partial: Partial<InformationEntity>) {
Object.assign(this, partial);
}
}
import { AddressEntity } from './address.entity';
export class StudentEntity {
completeName: string;
phone: string;
birthDate: Date;
address: AddressEntity;
FormationAndSpecialty: string;
email: string;
socialSecurityNumber: string;
constructor(partial: Partial<StudentEntity>) {
Object.assign(this, partial);
}
}
export class TrackingEntity {
state: string;
studentEntersInternshipInformation?: boolean;
responsibleAcceptsInternshipInformation?: boolean;
secretaryEstablishesInternshipAgreement?: string;
studentSignsInternshipAgreement?: string;
responsibleSignsInternshipAgreement?: string;
companySignsInternshipAgreement?: string;
deanSignsInternshipAgreement?: string;
constructor(partial: Partial<TrackingEntity>) {
Object.assign(this, partial);
}
}
import {
Controller,
Get,
Post,
Put,
Delete,
Param,
Body,
UseInterceptors,
} from '@nestjs/common';
import { BAD_TRACKING_STATE } from 'src/shared/HttpError';
import * as InternshipStates from 'src/shared/InternshipState';
import { HttpInterceptor } from '../interceptors/http.interceptor';
import { CreateInternshipDto } from './dto/create-internship.dto';
import { InternshipEntity } from './entities/internship.entity';
import { InternshipService } from './internships.service';
@Controller('internships')
@UseInterceptors(HttpInterceptor)
export class InternshipsController {
constructor(private readonly _internshipsService: InternshipService) {}
@Get()
findAll(): Promise<InternshipEntity[] | void> {
return this._internshipsService.findAll();
}
@Get(':studentId')
findOne(
@Param() params: { studentId: string },
): Promise<InternshipEntity | void> {
return this._internshipsService.findOne(params.studentId);
}
@Post()
create(
@Body() internshipDto: CreateInternshipDto,
): Promise<InternshipEntity> {
return this._internshipsService.create(internshipDto);
}
@Put(':studentId')
update(
@Param() params: { studentId: string },
@Body() internshipDto: CreateInternshipDto,
): Promise<InternshipEntity | void> {
return this._internshipsService.update(params.studentId, internshipDto);
}
@Put(':studentId/tracking')
updateState(
@Param() params: { studentId: string },
@Body() body: { state: string; content?: string | boolean },
): Promise<InternshipEntity | void> {
if (!InternshipStates.isStateValid(body.state))
throw BAD_TRACKING_STATE(body.state);
// AMINE : Handle PDF file upload -> save file in /pdf/ folder and set content as local file URL. In case of step with no file, set content as true/false
return this._internshipsService.updateTracking(
params.studentId,
body.state,
body.content,
);
}
@Delete(':studentId')
delete(
@Param() params: { studentId: string },
): Promise<InternshipEntity | void> {
return this._internshipsService.delete(params.studentId);
}
}
import { Module, Logger } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { InternshipDao } from './dao/internships.dao';
import { InternshipsController } from './internships.controller';
import { InternshipService } from './internships.service';
import { Internship, InternshipSchema } from './schemas/internship.schema';
@Module({
imports: [
MongooseModule.forFeature([
{ name: Internship.name, schema: InternshipSchema },
]),
],
controllers: [InternshipsController],
providers: [InternshipService, InternshipDao, Logger],
})
export class InternshipsModule {}
import { Injectable } from '@nestjs/common';
import { InternshipDao } from './dao/internships.dao';
import { CreateInternshipDto } from './dto/create-internship.dto';
import { InternshipEntity } from './entities/internship.entity';
@Injectable()
export class InternshipService {
constructor(private readonly _internshipsDao: InternshipDao) {}
findAll = (): Promise<InternshipEntity[] | void> =>
this._internshipsDao.find();
findOne = (studentId: string): Promise<InternshipEntity | void> =>
this._internshipsDao.findByStudentId(studentId);
create = (internship: CreateInternshipDto): Promise<InternshipEntity> =>
this._internshipsDao.save(internship);
update = (
studentId: string,
internship: CreateInternshipDto,
): Promise<InternshipEntity | void> =>
this._internshipsDao.findByStudentIdAndUpdate(studentId, internship);
updateTracking = (
studentId: string,
state: string,
content: string | boolean,
): Promise<InternshipEntity | void> =>
this._internshipsDao.findByStudentIdAndUpdateTracking(
studentId,
state,
content,
);
delete = (studentId: string): Promise<InternshipEntity | void> =>
this._internshipsDao.findByStudentIdAndRemove(studentId);
}
import { Document } from 'mongoose';
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import {
Information,
InformationSchema,
} from './nested-schemas/information.schema';
import { Tracking, TrackingSchema } from './nested-schemas/tracking.schema';
export type InternshipDocument = Internship & Document;
@Schema({
toJSON: {
virtuals: true,
transform: (doc: any, ret: any) => {
delete ret._id;
},
},
})
export class Internship {
@Prop({ type: String, required: true, trim: true })
studentId: string;
@Prop({ type: InformationSchema, required: true, trim: true })
information: Information;
@Prop({ type: TrackingSchema, required: true, trim: true })
tracking: Tracking;
}
export const InternshipSchema = SchemaFactory.createForClass(Internship);
import { Document } from 'mongoose';
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
// Nested Schema
@Schema({ _id: false })
export class Address extends Document {
@Prop({ type: String, required: true, trim: true })
street: string;
@Prop({ type: String, required: true, trim: true })
postalCode: string;
@Prop({ type: String, required: true, trim: true })
city: string;
@Prop({ type: String, required: true, trim: true })
country: string;
}
export const AddressSchema = SchemaFactory.createForClass(Address);
import { Document } from 'mongoose';
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Address, AddressSchema } from './address.schema';
// Nested Schema
@Schema({ _id: false })
export class Affectation extends Document {
@Prop({ type: String, required: true, trim: true })
service: string;
@Prop({ type: String, required: true, trim: true })
responsibleName: string;
@Prop({ type: String, required: true, trim: true })
responsibleEmail: string;
@Prop({ type: String, required: true, trim: true })
responsiblePhone: string;
@Prop({ type: String, required: true, trim: true })
responsibleFunction: string;
@Prop({ type: Date, required: true, trim: true })
dateStart: Date;
@Prop({ type: Date, required: true, trim: true })
dateEnd: Date;
@Prop({ type: AddressSchema, required: true, trim: true })
address: Address;
}
export const AffectationSchema = SchemaFactory.createForClass(Affectation);
import { Document } from 'mongoose';
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Address, AddressSchema } from './address.schema';
// Nested Schema
@Schema({ _id: false })
export class Company extends Document {
@Prop({ type: String, required: true, trim: true })
ceoName: string;
@Prop({ type: String, required: true, trim: true })
companyName: string;
@Prop({ type: String, required: true, trim: true })
hrContactName: string;
@Prop({ type: String, required: true, trim: true })
hrContactEmail: string;
@Prop({ type: AddressSchema, required: true, trim: true })
address: Address;
}
export const CompanySchema = SchemaFactory.createForClass(Company);
import { Document } from 'mongoose';
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
// Nested Schema
@Schema({ _id: false })
export class Compensation extends Document {
@Prop({ type: String, required: true, trim: true })
gratificationAmount: string;
@Prop({ type: String, required: true, trim: true })
modalities: string;
@Prop({ type: String, required: true, trim: true })
othersAdvantages: string;
}
export const CompensationSchema = SchemaFactory.createForClass(Compensation);
import { Document } from 'mongoose';
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Student, StudentSchema } from './student.schema';
import { Company, CompanySchema } from './company.schema';
import { Affectation, AffectationSchema } from './affectation.schema';
import { Compensation, CompensationSchema } from './compensation.schema';
// Nested Schema
@Schema({ _id: false })
export class Information extends Document {
@Prop({ type: StudentSchema, required: true, trim: true })
student: Student;
@Prop({ type: CompanySchema, required: true, trim: true })
company: Company;
@Prop({ type: AffectationSchema, required: true, trim: true })
affectation: Affectation;
@Prop({ type: CompensationSchema, required: true, trim: true })
compensation: Compensation;
@Prop({ type: String, required: true, trim: true })
internshipDescription: string;
}
export const InformationSchema = SchemaFactory.createForClass(Information);
import { Document } from 'mongoose';
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Address, AddressSchema } from './address.schema';
// Nested Schema
@Schema({ _id: false })
export class Student extends Document {
@Prop({ type: String, required: true, trim: true })
completeName: string;
@Prop({ type: String, required: true, trim: true })
phone: string;
@Prop({ type: Date, required: true, trim: true })
birthDate: Date;
@Prop({ type: AddressSchema, required: true, trim: true })
address: Address;
@Prop({ type: String, required: true, trim: true })
FormationAndSpecialty: string;
@Prop({ type: String, required: true, trim: true })
email: string;
@Prop({ type: String, required: true, trim: true })
socialSecurityNumber: string;
}
export const StudentSchema = SchemaFactory.createForClass(Student);
import { Document } from 'mongoose';
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
// Nested Schema
@Schema({ _id: false })
export class Tracking extends Document {
@Prop({ type: String, required: true, trim: true })
state: string;
@Prop({ type: Boolean, required: false, trim: true })
studentEntersInternshipInformation?: boolean;
@Prop({ type: Boolean, required: false, trim: true })
responsibleAcceptsInternshipInformation?: boolean;
@Prop({ type: String, required: false, trim: true })
secretaryEstablishesInternshipAgreement?: string;
@Prop({ type: String, required: false, trim: true })
studentSignsInternshipAgreement?: string;
@Prop({ type: String, required: false, trim: true })
responsibleSignsInternshipAgreement?: string;
@Prop({ type: String, required: false, trim: true })
companySignsInternshipAgreement?: string;
@Prop({ type: String, required: false, trim: true })
deanSignsInternshipAgreement?: string;
}
export const TrackingSchema = SchemaFactory.createForClass(Tracking);
import { ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { server } from './config';
import config from './config';
async function bootstrap() {
const env = process.env.NODE_ENV;
const app = await NestFactory.create(AppModule);
if (env === 'dev') {
app.enableCors();
} else if (env === 'prod') {
// enableCors for SPECIFIC origin only, aka the way it's supposed to be
} else {
// unknown environement ?
}
await app.useGlobalPipes(
new ValidationPipe({
whitelist: true,
forbidNonWhitelisted: true,
}),
);
await app.listen(server.port);
await app.listen(config.server.port);
}
bootstrap();
\ No newline at end of file
bootstrap();
import {
HttpException,
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) =>
new HttpException(reason, errorStatus);
export const STATE_STUDENT_ENTERS_INTERNSHIP_INFORMATION =
'student-enters-internship-information';
export const STATE_RESPONSIBLE_ACCEPTS_INTERNSHIP_INFORMATION =
'responsible-accepts-internship-information';
export const STATE_SECRETARY_ESTABLISHES_INTERNSHIP_AGREEMENT =
'secretary-establishes-internship-agreement';
export const STATE_STUDENT_SIGNS_INTERNSHIP_AGREEMENT =
'student-signs-internship-agreement';
export const STATE_RESPONSIBLE_SIGNS_INTERNSHIP_AGREEMENT =
'responsible-signs-internship-agreement';
export const STATE_COMPANY_SIGNS_INTERNSHIP_AGREEMENT =
'company-signs-internship-agreement';
export const STATE_DEAN_SIGNS_INTERNSHIP_AGREEMENT =
'dean-signs-internship-agreement';
export const STATES = [
STATE_STUDENT_ENTERS_INTERNSHIP_INFORMATION,
STATE_RESPONSIBLE_ACCEPTS_INTERNSHIP_INFORMATION,
STATE_SECRETARY_ESTABLISHES_INTERNSHIP_AGREEMENT,
STATE_STUDENT_SIGNS_INTERNSHIP_AGREEMENT,
STATE_RESPONSIBLE_SIGNS_INTERNSHIP_AGREEMENT,
STATE_COMPANY_SIGNS_INTERNSHIP_AGREEMENT,
STATE_DEAN_SIGNS_INTERNSHIP_AGREEMENT,
];
export const isStateValid = (potentialState: string): boolean =>
STATES.includes(potentialState);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment