mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-06 15:55:02 +00:00
feat: add publication
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user