214 lines
7.7 KiB
JavaScript
214 lines
7.7 KiB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
};
|
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
};
|
|
import { Body, Controller, Delete, Get, HttpCode, Module, Param, Patch, Post, Put, Query, } from "@nestjs/common";
|
|
import { categoryInputSchema, productInputSchema, productListQuerySchema, reorderSchema, } from "@imen/shared";
|
|
import { z } from "zod";
|
|
import { AdminAuth, CurrentUser, Roles } from "../common/auth.js";
|
|
import { IdPipe, ZodPipe } from "../common/zod.pipe.js";
|
|
import { MediaModule } from "../media/media.controller.js";
|
|
import { CategoriesService } from "./categories.service.js";
|
|
import { ProductsService } from "./products.service.js";
|
|
const publishSchema = z.object({ isPublished: z.boolean() });
|
|
let CategoriesController = class CategoriesController {
|
|
categories;
|
|
constructor(categories) {
|
|
this.categories = categories;
|
|
}
|
|
list() {
|
|
return this.categories.list();
|
|
}
|
|
get(id) {
|
|
return this.categories.get(id);
|
|
}
|
|
create(body, user) {
|
|
return this.categories.create(body, user.id);
|
|
}
|
|
async reorder(body, user) {
|
|
await this.categories.reorder(body.ids, user.id);
|
|
}
|
|
update(id, body, user) {
|
|
return this.categories.update(id, body, user.id);
|
|
}
|
|
async remove(id, user) {
|
|
await this.categories.remove(id, user.id);
|
|
}
|
|
};
|
|
__decorate([
|
|
Get(),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", []),
|
|
__metadata("design:returntype", void 0)
|
|
], CategoriesController.prototype, "list", null);
|
|
__decorate([
|
|
Get(":id"),
|
|
__param(0, Param("id", IdPipe)),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [Number]),
|
|
__metadata("design:returntype", void 0)
|
|
], CategoriesController.prototype, "get", null);
|
|
__decorate([
|
|
Post(),
|
|
__param(0, Body(new ZodPipe(categoryInputSchema))),
|
|
__param(1, CurrentUser()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [Object, Object]),
|
|
__metadata("design:returntype", void 0)
|
|
], CategoriesController.prototype, "create", null);
|
|
__decorate([
|
|
Post("reorder"),
|
|
HttpCode(204),
|
|
__param(0, Body(new ZodPipe(reorderSchema))),
|
|
__param(1, CurrentUser()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [Object, Object]),
|
|
__metadata("design:returntype", Promise)
|
|
], CategoriesController.prototype, "reorder", null);
|
|
__decorate([
|
|
Put(":id"),
|
|
__param(0, Param("id", IdPipe)),
|
|
__param(1, Body(new ZodPipe(categoryInputSchema))),
|
|
__param(2, CurrentUser()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [Number, Object, Object]),
|
|
__metadata("design:returntype", void 0)
|
|
], CategoriesController.prototype, "update", null);
|
|
__decorate([
|
|
Roles("ADMIN"),
|
|
Delete(":id"),
|
|
HttpCode(204),
|
|
__param(0, Param("id", IdPipe)),
|
|
__param(1, CurrentUser()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [Number, Object]),
|
|
__metadata("design:returntype", Promise)
|
|
], CategoriesController.prototype, "remove", null);
|
|
CategoriesController = __decorate([
|
|
AdminAuth(),
|
|
Controller("admin/categories"),
|
|
__metadata("design:paramtypes", [CategoriesService])
|
|
], CategoriesController);
|
|
export { CategoriesController };
|
|
let ProductsController = class ProductsController {
|
|
products;
|
|
constructor(products) {
|
|
this.products = products;
|
|
}
|
|
list(q) {
|
|
return this.products.list(q);
|
|
}
|
|
get(id) {
|
|
return this.products.get(id);
|
|
}
|
|
create(body, user) {
|
|
return this.products.create(body, user.id);
|
|
}
|
|
async reorder(body, user) {
|
|
await this.products.reorder(body.ids, user.id);
|
|
}
|
|
duplicate(id, user) {
|
|
return this.products.duplicate(id, user.id);
|
|
}
|
|
publish(id, body, user) {
|
|
return this.products.setPublished(id, body.isPublished, user.id);
|
|
}
|
|
update(id, body, user) {
|
|
return this.products.update(id, body, user.id);
|
|
}
|
|
async remove(id, user) {
|
|
await this.products.remove(id, user.id);
|
|
}
|
|
};
|
|
__decorate([
|
|
Get(),
|
|
__param(0, Query(new ZodPipe(productListQuerySchema))),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [Object]),
|
|
__metadata("design:returntype", void 0)
|
|
], ProductsController.prototype, "list", null);
|
|
__decorate([
|
|
Get(":id"),
|
|
__param(0, Param("id", IdPipe)),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [Number]),
|
|
__metadata("design:returntype", void 0)
|
|
], ProductsController.prototype, "get", null);
|
|
__decorate([
|
|
Post(),
|
|
__param(0, Body(new ZodPipe(productInputSchema))),
|
|
__param(1, CurrentUser()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [Object, Object]),
|
|
__metadata("design:returntype", void 0)
|
|
], ProductsController.prototype, "create", null);
|
|
__decorate([
|
|
Post("reorder"),
|
|
HttpCode(204),
|
|
__param(0, Body(new ZodPipe(reorderSchema))),
|
|
__param(1, CurrentUser()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [Object, Object]),
|
|
__metadata("design:returntype", Promise)
|
|
], ProductsController.prototype, "reorder", null);
|
|
__decorate([
|
|
Post(":id/duplicate"),
|
|
__param(0, Param("id", IdPipe)),
|
|
__param(1, CurrentUser()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [Number, Object]),
|
|
__metadata("design:returntype", void 0)
|
|
], ProductsController.prototype, "duplicate", null);
|
|
__decorate([
|
|
Patch(":id/publish"),
|
|
__param(0, Param("id", IdPipe)),
|
|
__param(1, Body(new ZodPipe(publishSchema))),
|
|
__param(2, CurrentUser()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [Number, Object, Object]),
|
|
__metadata("design:returntype", void 0)
|
|
], ProductsController.prototype, "publish", null);
|
|
__decorate([
|
|
Put(":id"),
|
|
__param(0, Param("id", IdPipe)),
|
|
__param(1, Body(new ZodPipe(productInputSchema))),
|
|
__param(2, CurrentUser()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [Number, Object, Object]),
|
|
__metadata("design:returntype", void 0)
|
|
], ProductsController.prototype, "update", null);
|
|
__decorate([
|
|
Roles("ADMIN"),
|
|
Delete(":id"),
|
|
HttpCode(204),
|
|
__param(0, Param("id", IdPipe)),
|
|
__param(1, CurrentUser()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [Number, Object]),
|
|
__metadata("design:returntype", Promise)
|
|
], ProductsController.prototype, "remove", null);
|
|
ProductsController = __decorate([
|
|
AdminAuth(),
|
|
Controller("admin/products"),
|
|
__metadata("design:paramtypes", [ProductsService])
|
|
], ProductsController);
|
|
export { ProductsController };
|
|
let CatalogModule = class CatalogModule {
|
|
};
|
|
CatalogModule = __decorate([
|
|
Module({
|
|
imports: [MediaModule],
|
|
controllers: [CategoriesController, ProductsController],
|
|
providers: [CategoriesService, ProductsService],
|
|
})
|
|
], CatalogModule);
|
|
export { CatalogModule };
|
|
//# sourceMappingURL=catalog.module.js.map
|