diff --git a/src/internships/internships.controller.ts b/src/internships/internships.controller.ts index 3db74f04f2bddd9213935ca4e5cde9c0590260e7..58a18914f0cee611d391c4452336ef293d970a64 100644 --- a/src/internships/internships.controller.ts +++ b/src/internships/internships.controller.ts @@ -60,13 +60,19 @@ export class InternshipsController { // uploads even if invalid state... @Put(':studentId/:state') @UseInterceptors( - FileInterceptor('pdf', { + FileInterceptor('file', { storage: diskStorage({ destination: './files', filename: (_req, _file, cb) => { return cb(null, `${v4()}.pdf`); }, }), + fileFilter: (req, file, cb) => { + if (!file.originalname.match(/\.pdf$/)) { + return cb(new Error('Only PDF files are allowed!'), false); + } + cb(null, true); + }, }), ) updateState( diff --git a/src/login/login.controller.ts b/src/login/login.controller.ts index 3722154a8ee47b218a44efe18f13273448d6e028..a5e5e0bc37f729e348aeebfbb610c8816ef60f13 100644 --- a/src/login/login.controller.ts +++ b/src/login/login.controller.ts @@ -11,7 +11,7 @@ export class LoginController { // @UseGuards(AuthGuard('local')) @Post() async login(@Body() req: Login) { - console.log('controller ' + req.email + req.passwordHash); + // console.log('controller ' + req.email + req.passwordHash); return this.loginService.login(req); } } diff --git a/src/login/login.module.ts b/src/login/login.module.ts index d7ab1bb84d9ed57786230c2a120fa9ad470b937e..c31f30af502394105a5772fabdcbac2c54e55a6c 100644 --- a/src/login/login.module.ts +++ b/src/login/login.module.ts @@ -15,7 +15,7 @@ import { JwtStrategy } from './jwt.strategy'; PassportModule, JwtModule.register({ secret: jwtConstants.secret, - signOptions: { expiresIn: '300s' }, + signOptions: { expiresIn: '3600s' }, }), ], controllers: [LoginController], diff --git a/src/people/dto/create-people.dto.ts b/src/people/dto/create-people.dto.ts index 00d43b85b85a59e50f67f5cbc41f35602080222e..5906a213fb87b974f7d534e4ad99f33547691fed 100644 --- a/src/people/dto/create-people.dto.ts +++ b/src/people/dto/create-people.dto.ts @@ -1,6 +1,11 @@ -import { IsString, IsNotEmpty, IsOptional } from 'class-validator'; +import { IsBoolean, IsString, IsNotEmpty, IsOptional, IsNumber } from 'class-validator'; export class CreatePeopleDto { + + @IsNumber() + @IsNotEmpty() + ine: number; + @IsString() @IsNotEmpty() firstname: string; @@ -15,7 +20,7 @@ export class CreatePeopleDto { @IsString() @IsNotEmpty() email: string; - + @IsOptional() role: number; } diff --git a/src/people/dto/update-people.dto.ts b/src/people/dto/update-people.dto.ts index 4097f1e2b7647a6f1f8253e6f3690b404d60ab10..71aa9c1c662dde5a0afdb67f08d4d4951ffe88fd 100644 --- a/src/people/dto/update-people.dto.ts +++ b/src/people/dto/update-people.dto.ts @@ -1,23 +1,28 @@ -import { IsOptional, IsString, IsNotEmpty } from 'class-validator'; - -export class UpdatePeopleDto { - @IsString() - @IsOptional() - firstname: string; - - @IsString() - @IsOptional() - lastname: string; - - @IsString() - @IsOptional() - email: string; - - @IsString() - @IsOptional() - passwordHash: string; - - @IsOptional() - role: number; - -} \ No newline at end of file +import { IsOptional, IsString, IsNotEmpty, IsNumber } from 'class-validator'; + +export class UpdatePeopleDto { + + @IsNumber() + @IsNotEmpty() + ine: number; + + @IsString() + @IsOptional() + firstname: string; + + @IsString() + @IsOptional() + lastname: string; + + @IsString() + @IsOptional() + email: string; + + @IsString() + @IsOptional() + passwordHash: string; + + @IsOptional() + role: number; + +} diff --git a/src/people/entities/people.entity.ts b/src/people/entities/people.entity.ts index 38dc121450f753bfb0ecd772e399a4a9f12c2301..273de2ed64bed9b116d6640c0a609323d5353cf5 100644 --- a/src/people/entities/people.entity.ts +++ b/src/people/entities/people.entity.ts @@ -2,6 +2,7 @@ import { People } from '../schemas/people.schema'; export class PeopleEntity { _id: string; + ine: number; firstname: string; lastname: string; email: string; diff --git a/src/people/schemas/people.schema.ts b/src/people/schemas/people.schema.ts index 09d9a5f8a4178a5f5d2050222b031acf016bb5fa..98f636ec948f9ba5a74f353339f38ded6c32d718 100644 --- a/src/people/schemas/people.schema.ts +++ b/src/people/schemas/people.schema.ts @@ -1,58 +1,63 @@ -import * as mongoose from 'mongoose'; -import { Document } from 'mongoose'; -import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; - -export type PeopleDocument = People & Document; - -@Schema({ - toJSON: { - virtuals: true, - transform: (doc: any, ret: any) => { - delete ret._id; - }, - }, -}) -export class People { - @Prop({ - type: mongoose.Schema.Types.ObjectId, - auto: true, - }) - _id: any; - - @Prop({ - type: String, - required: true, - trim: true, - minlength: 2, - }) firstname: string; - - @Prop({ - type: String, - required: true, - trim: true, - minlength: 2, - }) lastname: string; - - @Prop({ - type: String, - required: true, - trim: true, - minlength: 2, - }) email: string; - - @Prop({ - type: String, - trim: true, - minlength: 2, - }) passwordHash: string; - - @Prop({ - type: Number, - required: true, - }) role: number; - -} - -export const PeopleSchema = SchemaFactory.createForClass(People); - -PeopleSchema.index({}); \ No newline at end of file +import * as mongoose from 'mongoose'; +import { Document } from 'mongoose'; +import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; + +export type PeopleDocument = People & Document; + +@Schema({ + toJSON: { + virtuals: true, + transform: (doc: any, ret: any) => { + delete ret._id; + }, + }, +}) +export class People { + @Prop({ + type: mongoose.Schema.Types.ObjectId, + auto: true, + }) + _id: any; + + @Prop({ + type: Number, + required: true, + }) ine: number; + + @Prop({ + type: String, + required: true, + trim: true, + minlength: 2, + }) firstname: string; + + @Prop({ + type: String, + required: true, + trim: true, + minlength: 2, + }) lastname: string; + + @Prop({ + type: String, + required: true, + trim: true, + minlength: 2, + }) email: string; + + @Prop({ + type: String, + trim: true, + minlength: 2, + }) passwordHash: string; + + @Prop({ + type: Number, + required: true, + }) role: number; + +} + +export const PeopleSchema = SchemaFactory.createForClass(People); + +PeopleSchema.index({}); diff --git a/src/resources/resources.controller.ts b/src/resources/resources.controller.ts index afd5df97a65ed6741e182a9a5984392acaa1bf95..332d8bb8f4227119da63c4ebbf01ad926d25bf5f 100644 --- a/src/resources/resources.controller.ts +++ b/src/resources/resources.controller.ts @@ -19,7 +19,7 @@ export class ResourcesController { @Param('filename') filename, @Res({ passthrough: true }) res: Response, ): StreamableFile { - const filepath = `files\\${filename}`; + const filepath = `files/${filename}`; if (!existsSync(filepath)) throw NOT_FOUND; const file = createReadStream(filepath); res.set({