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

feat: Added Backend support for Internships. tested: adding, reading. Not final

parent befe1af5
No related branches found
No related tags found
1 merge request!5Crud internship
This commit is part of merge request !5. Comments created here will be created in the context of that merge request.
Showing
with 452 additions and 2 deletions
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
"build": "nest build", "build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start", "start": "nest start",
"start:dev": "nest start --watch", "start:dev": "cross-env NODE_ENV=dev nest start --watch",
"start:debug": "nest start --debug --watch", "start:debug": "nest start --debug --watch",
"start:prod": "node dist/main", "start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
"@types/supertest": "^2.0.11", "@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^5.0.0", "@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0", "@typescript-eslint/parser": "^5.0.0",
"cross-env": "^7.0.3",
"eslint": "^8.0.1", "eslint": "^8.0.1",
"eslint-config-prettier": "^8.3.0", "eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0", "eslint-plugin-prettier": "^4.0.0",
......
...@@ -3,8 +3,14 @@ import { MongooseModule } from '@nestjs/mongoose'; ...@@ -3,8 +3,14 @@ import { MongooseModule } from '@nestjs/mongoose';
import { mongodb } from './config'; import { mongodb } from './config';
import { PeopleModule } from './people/people.module'; import { PeopleModule } from './people/people.module';
import { GroupsModule } from './groups/groups.module'; import { GroupsModule } from './groups/groups.module';
import { InternshipsModule } from './internships/internships.module';
@Module({ @Module({
imports: [PeopleModule, GroupsModule, MongooseModule.forRoot(mongodb.uri)], imports: [
PeopleModule,
GroupsModule,
InternshipsModule,
MongooseModule.forRoot(mongodb.uri),
],
}) })
export class AppModule {} export class AppModule {}
import {
Injectable,
NotFoundException,
InternalServerErrorException,
} from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { CreateInternshipDto } from '../dto/create-internship.dto';
import { InternshipDto } from '../dto/internship.dto';
import { TrackingDto } from '../dto/nested-create/tracking.dto';
import { Internship } from '../schemas/internship.schema';
@Injectable()
export class InternshipDao {
constructor(
@InjectModel(Internship.name)
private readonly _groupModel: Model<Internship>,
) {}
find = (): Promise<Internship[]> =>
new Promise((resolve, reject) => {
this._groupModel.find({}, {}, {}, (err, value) => {
if (err) reject(err.message);
if (!value) reject('No values');
resolve(value);
});
});
findByStudentId = (studentId: string): Promise<Internship | void> =>
new Promise((resolve, reject) => {
this._groupModel.findOne({ studentId }, {}, {}, (err, value) => {
if (err) reject(err.message);
if (!value) reject(new NotFoundException());
resolve(value);
});
});
save = (internship: CreateInternshipDto): Promise<Internship> =>
new Promise((resolve, reject) => {
// do smth
const _internship: InternshipDto = {
...internship,
tracking: {
state: 'state-1',
status: 'pending',
},
};
new this._groupModel(_internship).save((err, value) => {
if (err) reject(err.message);
if (!value) reject(new InternalServerErrorException());
resolve(value);
});
});
findByStudentIdAndUpdate = (
studentId: string,
internship: InternshipDto,
): Promise<Internship | void> =>
new Promise((resolve, reject) => {
this._groupModel.findOneAndReplace(
{ studentId },
internship,
{
new: true,
runValidators: true,
},
(err, value) => {
if (err) reject(err.message);
resolve(value);
},
);
});
findByStudentIdAndRemove = (studentId: string): Promise<Internship | void> =>
new Promise((resolve, reject) => {
this._groupModel.findOneAndDelete({ studentId }, {}, (err) => {
if (err) reject(err.message);
resolve();
});
});
}
import { Type } from 'class-transformer';
import {
IsString,
IsNotEmpty,
IsDefined,
IsNotEmptyObject,
ValidateNested,
} from 'class-validator';
import { InformationDto } from './nested-create/information.dto';
export class CreateInternshipDto {
@IsString()
@IsNotEmpty()
studentId: string;
@IsDefined()
@IsNotEmptyObject()
@ValidateNested()
@Type(() => InformationDto)
information: InformationDto;
}
import { Type } from 'class-transformer';
import {
IsString,
IsNotEmpty,
IsDefined,
IsNotEmptyObject,
ValidateNested,
} from 'class-validator';
import { InformationDto } from './nested-create/information.dto';
import { TrackingDto } from './nested-create/tracking.dto';
export class InternshipDto {
@IsString()
@IsNotEmpty()
studentId: string;
@IsDefined()
@IsNotEmptyObject()
@ValidateNested()
@Type(() => InformationDto)
information: InformationDto;
@IsDefined()
@IsNotEmptyObject()
@ValidateNested()
@Type(() => TrackingDto)
tracking: TrackingDto;
}
import { IsString, IsNotEmpty } from 'class-validator';
export class AddressDto {
@IsString()
@IsNotEmpty()
street: string;
@IsString()
@IsNotEmpty()
city: string;
@IsString()
@IsNotEmpty()
postalCode: string;
@IsString()
@IsNotEmpty()
country: string;
}
import { Type } from 'class-transformer';
import {
IsString,
IsNotEmpty,
IsDateString,
IsDefined,
IsNotEmptyObject,
ValidateNested,
} from 'class-validator';
import { AddressDto } from './address.dto';
export class AffectationDto {
@IsString()
@IsNotEmpty()
service: string;
@IsString()
@IsNotEmpty()
responsibleName: string;
@IsString()
@IsNotEmpty()
responsibleEmail: string;
@IsString()
@IsNotEmpty()
responsiblePhone: string;
@IsString()
@IsNotEmpty()
responsibleFunction: string;
@IsDateString()
@IsNotEmpty()
dateStart: Date;
@IsDateString()
@IsNotEmpty()
dateEnd: Date;
@IsDefined()
@IsNotEmptyObject()
@ValidateNested()
@Type(() => AddressDto)
address: AddressDto;
}
import { Type } from 'class-transformer';
import {
IsString,
IsNotEmpty,
IsDefined,
IsNotEmptyObject,
ValidateNested,
} from 'class-validator';
import { AddressDto } from './address.dto';
export class CompanyDto {
@IsString()
@IsNotEmpty()
ceoName: string;
@IsString()
@IsNotEmpty()
companyName: string;
@IsString()
@IsNotEmpty()
hrContactName: string;
@IsString()
@IsNotEmpty()
hrContactEmail: string;
@IsDefined()
@IsNotEmptyObject()
@ValidateNested()
@Type(() => AddressDto)
address: AddressDto;
}
import { IsString, IsNotEmpty } from 'class-validator';
export class CompensationDto {
@IsString()
@IsNotEmpty()
gratificationAmount: string;
@IsString()
@IsNotEmpty()
modalities: string;
@IsString()
@IsNotEmpty()
othersAdvantages: string;
}
import { Type } from 'class-transformer';
import {
IsString,
IsNotEmpty,
IsDefined,
IsNotEmptyObject,
ValidateNested,
} from 'class-validator';
import { AffectationDto } from './affectation.dto';
import { CompanyDto } from './company.dto';
import { CompensationDto } from './compensation.dto';
import { StudentDto } from './student.dto';
export class InformationDto {
@IsDefined()
@IsNotEmptyObject()
@ValidateNested()
@Type(() => StudentDto)
student: StudentDto;
@IsDefined()
@IsNotEmptyObject()
@ValidateNested()
@Type(() => CompanyDto)
company: CompanyDto;
@IsDefined()
@IsNotEmptyObject()
@ValidateNested()
@Type(() => AffectationDto)
affectation: AffectationDto;
@IsDefined()
@IsNotEmptyObject()
@ValidateNested()
@Type(() => CompensationDto)
compensation: CompensationDto;
@IsString()
@IsNotEmpty()
internshipDescription: string;
}
import { Type } from 'class-transformer';
import {
IsString,
IsNotEmpty,
IsDateString,
IsDefined,
IsNotEmptyObject,
ValidateNested,
IsEmail,
IsAlphanumeric,
IsPhoneNumber,
} from 'class-validator';
import { AddressDto } from './address.dto';
export class StudentDto {
@IsString()
@IsNotEmpty()
completeName: string;
@IsString()
@IsPhoneNumber()
@IsNotEmpty()
phone: string;
@IsDateString()
@IsNotEmpty()
birthDate: Date;
@IsDefined()
@IsNotEmptyObject()
@ValidateNested()
@Type(() => AddressDto)
address: AddressDto;
@IsString()
@IsNotEmpty()
FormationAndSpecialty: string;
@IsString()
@IsEmail()
@IsNotEmpty()
email: string;
@IsString()
@IsAlphanumeric()
@IsNotEmpty()
socialSecurityNumber: string;
}
import { IsString, IsNotEmpty } from 'class-validator';
export class TrackingDto {
@IsString()
@IsNotEmpty()
status: string;
@IsString()
@IsNotEmpty()
state: string;
}
import { InformationEntity } from './nested-entities/information.entity';
import { TrackingEntity } from './nested-entities/tracking.entity';
export class InternshipEntity {
studentId: string;
information: InformationEntity;
tracking: TrackingEntity;
constructor(partial: Partial<InternshipEntity>) {
Object.assign(this, partial);
}
}
export class AddressEntity {
street: string;
postalCode: string;
city: string;
country: string;
constructor(partial: Partial<AddressEntity>) {
Object.assign(this, partial);
}
}
import { AddressEntity } from './address.entity';
export class AffectationEntity {
service: string;
responsibleName: string;
responsibleEmail: string;
responsiblePhone: string;
responsibleFunction: string;
dateStart: Date;
dateEnd: Date;
address: AddressEntity;
constructor(partial: Partial<AffectationEntity>) {
Object.assign(this, partial);
}
}
import { AddressEntity } from './address.entity';
export class CompanyEntity {
ceoName: string;
companyName: string;
hrContactName: string;
hrContactEmail: string;
address: AddressEntity;
constructor(partial: Partial<CompanyEntity>) {
Object.assign(this, partial);
}
}
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 {
status: string;
state: string;
constructor(partial: Partial<TrackingEntity>) {
Object.assign(this, partial);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment