mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-06 06:33:39 +00:00
77 lines
2.6 KiB
TypeScript
77 lines
2.6 KiB
TypeScript
import { CurrentUser } from "@edr/api-common";
|
|
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
Param,
|
|
ParseUUIDPipe,
|
|
Patch,
|
|
Post,
|
|
UploadedFile,
|
|
UseInterceptors,
|
|
} from "@nestjs/common";
|
|
import { FileInterceptor } from "@nestjs/platform-express";
|
|
import { ApiBearerAuth, ApiConsumes, ApiOperation, ApiTags } from "@nestjs/swagger";
|
|
import type { TCurrentUser } from "@tria-plc/api-common/modules/auth/types/current-user.type";
|
|
|
|
import { BookingStaff } from "../../common/booking-guards";
|
|
import { documentUploadMulterOptions } from "../../common/document-upload.options";
|
|
import { FREIGHT_PERMS } from "../../seed/freight-permissions.registry";
|
|
import { CreatePublicationDto } from "./dto/create-publication.dto";
|
|
import { UpdatePublicationDto } from "./dto/update-publication.dto";
|
|
import { PublicationsService } from "./publications.service";
|
|
|
|
const READ = [FREIGHT_PERMS.settings.publications.view, FREIGHT_PERMS.settings.publications.manage, FREIGHT_PERMS.admin];
|
|
const WRITE = [FREIGHT_PERMS.settings.publications.manage, FREIGHT_PERMS.admin];
|
|
|
|
@ApiTags("publications")
|
|
@ApiBearerAuth()
|
|
@Controller("publications")
|
|
export class PublicationsController {
|
|
constructor(private readonly service: PublicationsService) {}
|
|
|
|
@Get("admin")
|
|
@BookingStaff(READ)
|
|
@ApiOperation({ summary: "List every publication, published or not" })
|
|
list() {
|
|
return this.service.list();
|
|
}
|
|
|
|
@Post()
|
|
@BookingStaff(WRITE)
|
|
@UseInterceptors(FileInterceptor("file", documentUploadMulterOptions))
|
|
@ApiConsumes("multipart/form-data")
|
|
@ApiOperation({ summary: "Upload a new publication" })
|
|
create(
|
|
@UploadedFile() file: Express.Multer.File,
|
|
@Body() dto: CreatePublicationDto,
|
|
@CurrentUser() user: TCurrentUser,
|
|
) {
|
|
return this.service.create(file, dto, user?.id ?? null);
|
|
}
|
|
|
|
@Patch(":id")
|
|
@BookingStaff(WRITE)
|
|
@ApiOperation({ summary: "Update a publication's title, description, category, order or published state" })
|
|
update(@Param("id", ParseUUIDPipe) id: string, @Body() dto: UpdatePublicationDto) {
|
|
return this.service.update(id, dto);
|
|
}
|
|
|
|
@Post(":id/file")
|
|
@BookingStaff(WRITE)
|
|
@UseInterceptors(FileInterceptor("file", documentUploadMulterOptions))
|
|
@ApiConsumes("multipart/form-data")
|
|
@ApiOperation({ summary: "Replace a publication's file" })
|
|
replaceFile(@Param("id", ParseUUIDPipe) id: string, @UploadedFile() file: Express.Multer.File) {
|
|
return this.service.replaceFile(id, file);
|
|
}
|
|
|
|
@Delete(":id")
|
|
@BookingStaff(WRITE)
|
|
@ApiOperation({ summary: "Remove a publication" })
|
|
remove(@Param("id", ParseUUIDPipe) id: string) {
|
|
return this.service.remove(id);
|
|
}
|
|
}
|