137 lines
3.1 KiB
TypeScript
137 lines
3.1 KiB
TypeScript
import { Controller } from '@nestjs/common';
|
|
import { CatalogService } from './services/catalog.service';
|
|
import { MessagePattern } from '@nestjs/microservices';
|
|
import { PageQuery, UserInfo } from '@freeblox/shared';
|
|
import { ContentAssetType } from './enums/content-asset-type.enum';
|
|
import {
|
|
CreateContentRequest,
|
|
CreateContentRevisionRequest,
|
|
} from './interfaces/create-content-request.interface';
|
|
import { CreateContentService } from './services/create-content.service';
|
|
|
|
@Controller()
|
|
export class CatalogController {
|
|
constructor(
|
|
private readonly catalogService: CatalogService,
|
|
private readonly createContentService: CreateContentService,
|
|
) {}
|
|
|
|
// Getters
|
|
|
|
@MessagePattern('catalog.items.categories')
|
|
async getCatalogCategories() {
|
|
return this.catalogService.getCategoryTree();
|
|
}
|
|
|
|
@MessagePattern('catalog.items.byId')
|
|
async getItemById({ id, user }: { id: number; user?: UserInfo }) {
|
|
return this.catalogService.getCatalogItemById(id, user);
|
|
}
|
|
|
|
@MessagePattern('catalog.assets.byId')
|
|
async getItemAssets({
|
|
id,
|
|
type,
|
|
typeName,
|
|
}: {
|
|
id: number;
|
|
type?: ContentAssetType[];
|
|
typeName?: string[];
|
|
}) {
|
|
return this.catalogService.getCatalogItemAssets(id, type, typeName);
|
|
}
|
|
|
|
@MessagePattern('catalog.comments.byId')
|
|
async getItemComments({
|
|
id,
|
|
paging,
|
|
user,
|
|
}: {
|
|
id: number;
|
|
paging?: PageQuery;
|
|
user?: UserInfo;
|
|
}) {
|
|
return this.catalogService.getCatalogItemComments(id, paging, user);
|
|
}
|
|
|
|
@MessagePattern('catalog.votes.byId')
|
|
async getItemVotes({ id, user }: { id: number; user?: UserInfo }) {
|
|
return this.catalogService.getContentVotes(id, user);
|
|
}
|
|
|
|
// Actions
|
|
|
|
@MessagePattern('catalog.items.create')
|
|
async createItem({
|
|
body,
|
|
user,
|
|
files,
|
|
gameId,
|
|
}: {
|
|
body: CreateContentRequest;
|
|
user: UserInfo;
|
|
files?: Express.Multer.File[];
|
|
gameId?: number;
|
|
}) {
|
|
return this.createContentService.createContent(body, user, files, gameId);
|
|
}
|
|
|
|
@MessagePattern('catalog.items.createRevision')
|
|
async createItemRevision({
|
|
id,
|
|
body,
|
|
user,
|
|
files,
|
|
}: {
|
|
id: number;
|
|
body: CreateContentRevisionRequest;
|
|
user: UserInfo;
|
|
files?: Express.Multer.File[];
|
|
}) {
|
|
return this.createContentService.createContentRevision(
|
|
id,
|
|
body,
|
|
user,
|
|
files,
|
|
);
|
|
}
|
|
|
|
@MessagePattern('catalog.items.appendToRevision')
|
|
async appendToRevision({
|
|
id,
|
|
body,
|
|
user,
|
|
files,
|
|
}: {
|
|
id: number;
|
|
body: CreateContentRevisionRequest;
|
|
user: UserInfo;
|
|
files?: Express.Multer.File[];
|
|
}) {
|
|
return this.createContentService.addFilesToLatestRevision(
|
|
id,
|
|
body.files,
|
|
files,
|
|
user,
|
|
);
|
|
}
|
|
|
|
@MessagePattern('catalog.items.update')
|
|
async updateItem({
|
|
id,
|
|
body,
|
|
user,
|
|
}: {
|
|
id: number;
|
|
body: Partial<CreateContentRequest>;
|
|
user: UserInfo;
|
|
}) {
|
|
return this.createContentService.updateContentDetails(id, body, user);
|
|
}
|
|
|
|
@MessagePattern('catalog.items.publish')
|
|
async publishItem({ id, user }: { id: number; user: UserInfo }) {
|
|
return this.createContentService.publishContentItem(id, user);
|
|
}
|
|
}
|