128 lines
2.7 KiB
TypeScript
128 lines
2.7 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Get,
|
|
HttpStatus,
|
|
Param,
|
|
ParseUUIDPipe,
|
|
Post,
|
|
Put,
|
|
Query,
|
|
Res,
|
|
UploadedFile,
|
|
UseInterceptors,
|
|
} from '@nestjs/common';
|
|
import { RoleService } from './roles.service';
|
|
import { CommissionService } from './commission.service';
|
|
import { FileInterceptor } from '@nestjs/platform-express';
|
|
import { diskStorage } from 'multer';
|
|
import { editFileName } from '../helper/file-handler';
|
|
import { Public } from 'src/auth/public.decorator';
|
|
|
|
@Controller({
|
|
path: 'config',
|
|
version: '1',
|
|
})
|
|
export class ConfigurableController {
|
|
constructor(
|
|
private readonly roleService: RoleService,
|
|
private readonly commissionService: CommissionService,
|
|
) {}
|
|
|
|
@Get('/roles')
|
|
async findAll(
|
|
@Query('page') page: number,
|
|
@Query('pageSize') pageSize: number,
|
|
) {
|
|
const [data, count] = await this.roleService.findAllRoles(page, pageSize);
|
|
|
|
return {
|
|
data,
|
|
count,
|
|
statusCode: HttpStatus.OK,
|
|
message: 'success',
|
|
};
|
|
}
|
|
|
|
@Get('/commission')
|
|
async findCommission(
|
|
@Query('page') page: number,
|
|
@Query('pageSize') pageSize: number,
|
|
) {
|
|
const [data, count] = await this.commissionService.findAllCommission(
|
|
page,
|
|
pageSize,
|
|
);
|
|
|
|
return {
|
|
data,
|
|
count,
|
|
statusCode: HttpStatus.OK,
|
|
message: 'success',
|
|
};
|
|
}
|
|
|
|
@Get('/roles/for-membership')
|
|
async findAllForMembership(
|
|
@Query('page') page: number,
|
|
@Query('pageSize') pageSize: number,
|
|
) {
|
|
const [data, count] = await this.roleService.findAllRolesForCreateMember(
|
|
page,
|
|
pageSize,
|
|
);
|
|
|
|
return {
|
|
data,
|
|
count,
|
|
statusCode: HttpStatus.OK,
|
|
message: 'success',
|
|
};
|
|
}
|
|
|
|
@Public()
|
|
@Get('/image/:imgpath')
|
|
seeUploadedFile(@Param('imgpath') image, @Res() res) {
|
|
return res.sendFile(image, { root: './files' });
|
|
}
|
|
|
|
@Get(':id')
|
|
async findOne(@Param('id', ParseUUIDPipe) id: string) {
|
|
return {
|
|
data: await this.roleService.findOne(id),
|
|
statusCode: HttpStatus.OK,
|
|
message: 'success',
|
|
};
|
|
}
|
|
|
|
@Public()
|
|
@Post('/upload-files')
|
|
@UseInterceptors(
|
|
FileInterceptor('file', {
|
|
storage: diskStorage({
|
|
destination: './files',
|
|
filename: editFileName,
|
|
}),
|
|
}),
|
|
)
|
|
async uploadedFile(@UploadedFile() file: Express.Multer.File) {
|
|
const response = {
|
|
originalname: file,
|
|
filename: file.filename,
|
|
};
|
|
return response;
|
|
}
|
|
|
|
@Put('/commission/:id')
|
|
async updateCommission(
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@Body() request,
|
|
) {
|
|
return {
|
|
data: await this.commissionService.updateCommission(id, request),
|
|
statusCode: HttpStatus.OK,
|
|
message: 'success',
|
|
};
|
|
}
|
|
}
|