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

Merge branch 'master' into people-import

parents c7fd5165 313b5376
Branches
No related tags found
1 merge request!14Added the ability to import multiple people at once using JSON format.
......@@ -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(
......
......@@ -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);
}
}
......@@ -15,7 +15,7 @@ import { JwtStrategy } from './jwt.strategy';
PassportModule,
JwtModule.register({
secret: jwtConstants.secret,
signOptions: { expiresIn: '300s' },
signOptions: { expiresIn: '3600s' },
}),
],
controllers: [LoginController],
......
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;
}
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;
}
......@@ -2,6 +2,7 @@ import { People } from '../schemas/people.schema';
export class PeopleEntity {
_id: string;
ine: number;
firstname: string;
lastname: string;
email: string;
......
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({});
......@@ -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({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment