Deploy via committed dist: local Nest build, server runs with .env
Build on the developer machine without Docker, commit dist/, and run on the server with Dockerfile.dist plus compose env_file. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Vendored
+151
@@ -0,0 +1,151 @@
|
||||
import { CartsService } from './carts.service';
|
||||
import type { AuthPrincipal } from '../common/decorators/current-user.decorator';
|
||||
import { AddCartItemDto, UpdateCartItemMeterageDto, UpdateCartNotesDto } from './dto/cart.dto';
|
||||
export declare class CartsController {
|
||||
private readonly cartsService;
|
||||
constructor(cartsService: CartsService);
|
||||
getCart(user: AuthPrincipal): Promise<{
|
||||
id: string;
|
||||
userId: string;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
notes: string | undefined;
|
||||
items: {
|
||||
id: string;
|
||||
productId: string;
|
||||
catalogCode: string;
|
||||
productName: string;
|
||||
productCode: string;
|
||||
color: string;
|
||||
meterage: number;
|
||||
unitPrice: number | undefined;
|
||||
notes: string | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
}[];
|
||||
totalMeterage: number;
|
||||
itemCount: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}>;
|
||||
addItem(user: AuthPrincipal, dto: AddCartItemDto): Promise<{
|
||||
id: string;
|
||||
userId: string;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
notes: string | undefined;
|
||||
items: {
|
||||
id: string;
|
||||
productId: string;
|
||||
catalogCode: string;
|
||||
productName: string;
|
||||
productCode: string;
|
||||
color: string;
|
||||
meterage: number;
|
||||
unitPrice: number | undefined;
|
||||
notes: string | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
}[];
|
||||
totalMeterage: number;
|
||||
itemCount: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}>;
|
||||
updateItem(user: AuthPrincipal, itemId: string, dto: UpdateCartItemMeterageDto): Promise<{
|
||||
id: string;
|
||||
userId: string;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
notes: string | undefined;
|
||||
items: {
|
||||
id: string;
|
||||
productId: string;
|
||||
catalogCode: string;
|
||||
productName: string;
|
||||
productCode: string;
|
||||
color: string;
|
||||
meterage: number;
|
||||
unitPrice: number | undefined;
|
||||
notes: string | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
}[];
|
||||
totalMeterage: number;
|
||||
itemCount: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}>;
|
||||
removeItem(user: AuthPrincipal, itemId: string): Promise<{
|
||||
id: string;
|
||||
userId: string;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
notes: string | undefined;
|
||||
items: {
|
||||
id: string;
|
||||
productId: string;
|
||||
catalogCode: string;
|
||||
productName: string;
|
||||
productCode: string;
|
||||
color: string;
|
||||
meterage: number;
|
||||
unitPrice: number | undefined;
|
||||
notes: string | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
}[];
|
||||
totalMeterage: number;
|
||||
itemCount: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}>;
|
||||
updateNotes(user: AuthPrincipal, dto: UpdateCartNotesDto): Promise<{
|
||||
id: string;
|
||||
userId: string;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
notes: string | undefined;
|
||||
items: {
|
||||
id: string;
|
||||
productId: string;
|
||||
catalogCode: string;
|
||||
productName: string;
|
||||
productCode: string;
|
||||
color: string;
|
||||
meterage: number;
|
||||
unitPrice: number | undefined;
|
||||
notes: string | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
}[];
|
||||
totalMeterage: number;
|
||||
itemCount: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}>;
|
||||
clear(user: AuthPrincipal): Promise<{
|
||||
id: string;
|
||||
userId: string;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
notes: string | undefined;
|
||||
items: {
|
||||
id: string;
|
||||
productId: string;
|
||||
catalogCode: string;
|
||||
productName: string;
|
||||
productCode: string;
|
||||
color: string;
|
||||
meterage: number;
|
||||
unitPrice: number | undefined;
|
||||
notes: string | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
}[];
|
||||
totalMeterage: number;
|
||||
itemCount: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}>;
|
||||
}
|
||||
Vendored
+98
@@ -0,0 +1,98 @@
|
||||
"use strict";
|
||||
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); }
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CartsController = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const carts_service_1 = require("./carts.service");
|
||||
const auth_decorators_1 = require("../common/decorators/auth.decorators");
|
||||
const current_user_decorator_1 = require("../common/decorators/current-user.decorator");
|
||||
const cart_dto_1 = require("./dto/cart.dto");
|
||||
let CartsController = class CartsController {
|
||||
cartsService;
|
||||
constructor(cartsService) {
|
||||
this.cartsService = cartsService;
|
||||
}
|
||||
getCart(user) {
|
||||
return this.cartsService.getCart(user.id);
|
||||
}
|
||||
addItem(user, dto) {
|
||||
return this.cartsService.addItem(user.id, dto);
|
||||
}
|
||||
updateItem(user, itemId, dto) {
|
||||
return this.cartsService.updateItem(user.id, itemId, dto);
|
||||
}
|
||||
removeItem(user, itemId) {
|
||||
return this.cartsService.removeItem(user.id, itemId);
|
||||
}
|
||||
updateNotes(user, dto) {
|
||||
return this.cartsService.updateNotes(user.id, dto);
|
||||
}
|
||||
clear(user) {
|
||||
return this.cartsService.clearCart(user.id);
|
||||
}
|
||||
};
|
||||
exports.CartsController = CartsController;
|
||||
__decorate([
|
||||
(0, common_1.Get)(),
|
||||
__param(0, (0, current_user_decorator_1.CurrentUser)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], CartsController.prototype, "getCart", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('items'),
|
||||
__param(0, (0, current_user_decorator_1.CurrentUser)()),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, cart_dto_1.AddCartItemDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], CartsController.prototype, "addItem", null);
|
||||
__decorate([
|
||||
(0, common_1.Patch)('items/:itemId'),
|
||||
__param(0, (0, current_user_decorator_1.CurrentUser)()),
|
||||
__param(1, (0, common_1.Param)('itemId')),
|
||||
__param(2, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, String, cart_dto_1.UpdateCartItemMeterageDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], CartsController.prototype, "updateItem", null);
|
||||
__decorate([
|
||||
(0, common_1.Delete)('items/:itemId'),
|
||||
__param(0, (0, current_user_decorator_1.CurrentUser)()),
|
||||
__param(1, (0, common_1.Param)('itemId')),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, String]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], CartsController.prototype, "removeItem", null);
|
||||
__decorate([
|
||||
(0, common_1.Patch)('notes'),
|
||||
__param(0, (0, current_user_decorator_1.CurrentUser)()),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, cart_dto_1.UpdateCartNotesDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], CartsController.prototype, "updateNotes", null);
|
||||
__decorate([
|
||||
(0, common_1.Delete)(),
|
||||
__param(0, (0, current_user_decorator_1.CurrentUser)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], CartsController.prototype, "clear", null);
|
||||
exports.CartsController = CartsController = __decorate([
|
||||
(0, common_1.Controller)('carts'),
|
||||
(0, auth_decorators_1.AuthType)('customer'),
|
||||
__metadata("design:paramtypes", [carts_service_1.CartsService])
|
||||
], CartsController);
|
||||
//# sourceMappingURL=carts.controller.js.map
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"carts.controller.js","sourceRoot":"","sources":["../../src/carts/carts.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAQwB;AACxB,mDAA+C;AAC/C,0EAAgE;AAChE,wFAA0E;AAE1E,6CAIwB;AAIjB,IAAM,eAAe,GAArB,MAAM,eAAe;IACG;IAA7B,YAA6B,YAA0B;QAA1B,iBAAY,GAAZ,YAAY,CAAc;IAAG,CAAC;IAG3D,OAAO,CAAgB,IAAmB;QACxC,OAAO,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC5C,CAAC;IAGD,OAAO,CACU,IAAmB,EAC1B,GAAmB;QAE3B,OAAO,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IACjD,CAAC;IAGD,UAAU,CACO,IAAmB,EACjB,MAAc,EACvB,GAA8B;QAEtC,OAAO,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5D,CAAC;IAGD,UAAU,CACO,IAAmB,EACjB,MAAc;QAE/B,OAAO,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;IACvD,CAAC;IAGD,WAAW,CACM,IAAmB,EAC1B,GAAuB;QAE/B,OAAO,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IACrD,CAAC;IAGD,KAAK,CAAgB,IAAmB;QACtC,OAAO,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC9C,CAAC;CACF,CAAA;AA7CY,0CAAe;AAI1B;IADC,IAAA,YAAG,GAAE;IACG,WAAA,IAAA,oCAAW,GAAE,CAAA;;;;8CAErB;AAGD;IADC,IAAA,aAAI,EAAC,OAAO,CAAC;IAEX,WAAA,IAAA,oCAAW,GAAE,CAAA;IACb,WAAA,IAAA,aAAI,GAAE,CAAA;;6CAAM,yBAAc;;8CAG5B;AAGD;IADC,IAAA,cAAK,EAAC,eAAe,CAAC;IAEpB,WAAA,IAAA,oCAAW,GAAE,CAAA;IACb,WAAA,IAAA,cAAK,EAAC,QAAQ,CAAC,CAAA;IACf,WAAA,IAAA,aAAI,GAAE,CAAA;;qDAAM,oCAAyB;;iDAGvC;AAGD;IADC,IAAA,eAAM,EAAC,eAAe,CAAC;IAErB,WAAA,IAAA,oCAAW,GAAE,CAAA;IACb,WAAA,IAAA,cAAK,EAAC,QAAQ,CAAC,CAAA;;;;iDAGjB;AAGD;IADC,IAAA,cAAK,EAAC,OAAO,CAAC;IAEZ,WAAA,IAAA,oCAAW,GAAE,CAAA;IACb,WAAA,IAAA,aAAI,GAAE,CAAA;;6CAAM,6BAAkB;;kDAGhC;AAGD;IADC,IAAA,eAAM,GAAE;IACF,WAAA,IAAA,oCAAW,GAAE,CAAA;;;;4CAEnB;0BA5CU,eAAe;IAF3B,IAAA,mBAAU,EAAC,OAAO,CAAC;IACnB,IAAA,0BAAQ,EAAC,UAAU,CAAC;qCAEwB,4BAAY;GAD5C,eAAe,CA6C3B"}
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export declare class CartsModule {
|
||||
}
|
||||
Vendored
+23
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
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;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CartsModule = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const carts_controller_1 = require("./carts.controller");
|
||||
const carts_service_1 = require("./carts.service");
|
||||
let CartsModule = class CartsModule {
|
||||
};
|
||||
exports.CartsModule = CartsModule;
|
||||
exports.CartsModule = CartsModule = __decorate([
|
||||
(0, common_1.Module)({
|
||||
controllers: [carts_controller_1.CartsController],
|
||||
providers: [carts_service_1.CartsService],
|
||||
exports: [carts_service_1.CartsService],
|
||||
})
|
||||
], CartsModule);
|
||||
//# sourceMappingURL=carts.module.js.map
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"carts.module.js","sourceRoot":"","sources":["../../src/carts/carts.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,yDAAqD;AACrD,mDAA+C;AAOxC,IAAM,WAAW,GAAjB,MAAM,WAAW;CAAG,CAAA;AAAd,kCAAW;sBAAX,WAAW;IALvB,IAAA,eAAM,EAAC;QACN,WAAW,EAAE,CAAC,kCAAe,CAAC;QAC9B,SAAS,EAAE,CAAC,4BAAY,CAAC;QACzB,OAAO,EAAE,CAAC,4BAAY,CAAC;KACxB,CAAC;GACW,WAAW,CAAG"}
|
||||
Vendored
+153
@@ -0,0 +1,153 @@
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { AddCartItemDto, UpdateCartItemMeterageDto, UpdateCartNotesDto } from './dto/cart.dto';
|
||||
export declare class CartsService {
|
||||
private readonly prisma;
|
||||
constructor(prisma: PrismaService);
|
||||
getCart(userId: string): Promise<{
|
||||
id: string;
|
||||
userId: string;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
notes: string | undefined;
|
||||
items: {
|
||||
id: string;
|
||||
productId: string;
|
||||
catalogCode: string;
|
||||
productName: string;
|
||||
productCode: string;
|
||||
color: string;
|
||||
meterage: number;
|
||||
unitPrice: number | undefined;
|
||||
notes: string | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
}[];
|
||||
totalMeterage: number;
|
||||
itemCount: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}>;
|
||||
addItem(userId: string, dto: AddCartItemDto): Promise<{
|
||||
id: string;
|
||||
userId: string;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
notes: string | undefined;
|
||||
items: {
|
||||
id: string;
|
||||
productId: string;
|
||||
catalogCode: string;
|
||||
productName: string;
|
||||
productCode: string;
|
||||
color: string;
|
||||
meterage: number;
|
||||
unitPrice: number | undefined;
|
||||
notes: string | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
}[];
|
||||
totalMeterage: number;
|
||||
itemCount: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}>;
|
||||
updateItem(userId: string, itemId: string, dto: UpdateCartItemMeterageDto): Promise<{
|
||||
id: string;
|
||||
userId: string;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
notes: string | undefined;
|
||||
items: {
|
||||
id: string;
|
||||
productId: string;
|
||||
catalogCode: string;
|
||||
productName: string;
|
||||
productCode: string;
|
||||
color: string;
|
||||
meterage: number;
|
||||
unitPrice: number | undefined;
|
||||
notes: string | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
}[];
|
||||
totalMeterage: number;
|
||||
itemCount: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}>;
|
||||
removeItem(userId: string, itemId: string): Promise<{
|
||||
id: string;
|
||||
userId: string;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
notes: string | undefined;
|
||||
items: {
|
||||
id: string;
|
||||
productId: string;
|
||||
catalogCode: string;
|
||||
productName: string;
|
||||
productCode: string;
|
||||
color: string;
|
||||
meterage: number;
|
||||
unitPrice: number | undefined;
|
||||
notes: string | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
}[];
|
||||
totalMeterage: number;
|
||||
itemCount: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}>;
|
||||
updateNotes(userId: string, dto: UpdateCartNotesDto): Promise<{
|
||||
id: string;
|
||||
userId: string;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
notes: string | undefined;
|
||||
items: {
|
||||
id: string;
|
||||
productId: string;
|
||||
catalogCode: string;
|
||||
productName: string;
|
||||
productCode: string;
|
||||
color: string;
|
||||
meterage: number;
|
||||
unitPrice: number | undefined;
|
||||
notes: string | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
}[];
|
||||
totalMeterage: number;
|
||||
itemCount: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}>;
|
||||
clearCart(userId: string): Promise<{
|
||||
id: string;
|
||||
userId: string;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
notes: string | undefined;
|
||||
items: {
|
||||
id: string;
|
||||
productId: string;
|
||||
catalogCode: string;
|
||||
productName: string;
|
||||
productCode: string;
|
||||
color: string;
|
||||
meterage: number;
|
||||
unitPrice: number | undefined;
|
||||
notes: string | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
}[];
|
||||
totalMeterage: number;
|
||||
itemCount: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}>;
|
||||
private validateMeterage;
|
||||
private ensureCart;
|
||||
private mapCart;
|
||||
}
|
||||
Vendored
+188
@@ -0,0 +1,188 @@
|
||||
"use strict";
|
||||
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);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CartsService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const prisma_service_1 = require("../prisma/prisma.service");
|
||||
let CartsService = class CartsService {
|
||||
prisma;
|
||||
constructor(prisma) {
|
||||
this.prisma = prisma;
|
||||
}
|
||||
async getCart(userId) {
|
||||
const cart = await this.ensureCart(userId);
|
||||
return this.mapCart(cart);
|
||||
}
|
||||
async addItem(userId, dto) {
|
||||
const product = await this.prisma.product.findUnique({
|
||||
where: { id: dto.productId },
|
||||
include: {
|
||||
catalog: true,
|
||||
company: true,
|
||||
},
|
||||
});
|
||||
if (!product || !product.isActive) {
|
||||
throw new common_1.NotFoundException('محصول یافت نشد');
|
||||
}
|
||||
this.validateMeterage(product, dto.meterage);
|
||||
const cart = await this.ensureCart(userId);
|
||||
const existing = await this.prisma.cartItem.findUnique({
|
||||
where: {
|
||||
cartId_productId: { cartId: cart.id, productId: product.id },
|
||||
},
|
||||
});
|
||||
if (existing) {
|
||||
const newMeterage = existing.meterage + dto.meterage;
|
||||
this.validateMeterage(product, newMeterage);
|
||||
await this.prisma.cartItem.update({
|
||||
where: { id: existing.id },
|
||||
data: {
|
||||
meterage: newMeterage,
|
||||
notes: dto.notes?.trim() || existing.notes,
|
||||
unitPrice: product.basePrice,
|
||||
},
|
||||
});
|
||||
}
|
||||
else {
|
||||
await this.prisma.cartItem.create({
|
||||
data: {
|
||||
cartId: cart.id,
|
||||
productId: product.id,
|
||||
catalogCode: product.catalog.code,
|
||||
productName: product.name,
|
||||
productCode: product.code,
|
||||
color: product.color,
|
||||
meterage: dto.meterage,
|
||||
unitPrice: product.basePrice,
|
||||
notes: dto.notes?.trim() || null,
|
||||
companyId: product.companyId,
|
||||
companyName: product.company.name,
|
||||
},
|
||||
});
|
||||
}
|
||||
await this.prisma.cart.update({
|
||||
where: { id: cart.id },
|
||||
data: {
|
||||
companyId: product.companyId,
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
});
|
||||
return this.getCart(userId);
|
||||
}
|
||||
async updateItem(userId, itemId, dto) {
|
||||
const cart = await this.ensureCart(userId);
|
||||
const item = await this.prisma.cartItem.findFirst({
|
||||
where: { id: itemId, cartId: cart.id },
|
||||
include: { product: true },
|
||||
});
|
||||
if (!item)
|
||||
throw new common_1.NotFoundException('آیتم سبد یافت نشد');
|
||||
this.validateMeterage(item.product, dto.meterage);
|
||||
await this.prisma.cartItem.update({
|
||||
where: { id: itemId },
|
||||
data: {
|
||||
meterage: dto.meterage,
|
||||
notes: dto.notes === undefined ? undefined : dto.notes?.trim() || null,
|
||||
},
|
||||
});
|
||||
await this.prisma.cart.update({
|
||||
where: { id: cart.id },
|
||||
data: { updatedAt: new Date() },
|
||||
});
|
||||
return this.getCart(userId);
|
||||
}
|
||||
async removeItem(userId, itemId) {
|
||||
const cart = await this.ensureCart(userId);
|
||||
const item = await this.prisma.cartItem.findFirst({
|
||||
where: { id: itemId, cartId: cart.id },
|
||||
});
|
||||
if (!item)
|
||||
throw new common_1.NotFoundException('آیتم سبد یافت نشد');
|
||||
await this.prisma.cartItem.delete({ where: { id: itemId } });
|
||||
await this.prisma.cart.update({
|
||||
where: { id: cart.id },
|
||||
data: { updatedAt: new Date() },
|
||||
});
|
||||
return this.getCart(userId);
|
||||
}
|
||||
async updateNotes(userId, dto) {
|
||||
const cart = await this.ensureCart(userId);
|
||||
await this.prisma.cart.update({
|
||||
where: { id: cart.id },
|
||||
data: { notes: dto.notes?.trim() || null },
|
||||
});
|
||||
return this.getCart(userId);
|
||||
}
|
||||
async clearCart(userId) {
|
||||
const cart = await this.ensureCart(userId);
|
||||
await this.prisma.cartItem.deleteMany({ where: { cartId: cart.id } });
|
||||
await this.prisma.cart.update({
|
||||
where: { id: cart.id },
|
||||
data: { notes: null, companyId: null },
|
||||
});
|
||||
return this.getCart(userId);
|
||||
}
|
||||
validateMeterage(product, meterage) {
|
||||
if (meterage < product.minMeterage) {
|
||||
throw new common_1.BadRequestException(`حداقل متراژ برای ${product.name} برابر ${product.minMeterage} است`);
|
||||
}
|
||||
const rem = Math.round((meterage / product.orderMultiplier) * 1000) / 1000;
|
||||
if (Math.abs(rem - Math.round(rem)) > 1e-6) {
|
||||
throw new common_1.BadRequestException(`متراژ باید مضرب ${product.orderMultiplier} باشد`);
|
||||
}
|
||||
}
|
||||
async ensureCart(userId) {
|
||||
let cart = await this.prisma.cart.findFirst({
|
||||
where: { userId },
|
||||
include: { items: true },
|
||||
});
|
||||
if (!cart) {
|
||||
cart = await this.prisma.cart.create({
|
||||
data: { userId },
|
||||
include: { items: true },
|
||||
});
|
||||
}
|
||||
return cart;
|
||||
}
|
||||
mapCart(cart) {
|
||||
const companyName = cart.items[0]?.companyName;
|
||||
return {
|
||||
id: cart.id,
|
||||
userId: cart.userId,
|
||||
companyId: cart.companyId ?? cart.items[0]?.companyId,
|
||||
companyName: companyName ?? '',
|
||||
notes: cart.notes ?? undefined,
|
||||
items: cart.items.map((item) => ({
|
||||
id: item.id,
|
||||
productId: item.productId,
|
||||
catalogCode: item.catalogCode,
|
||||
productName: item.productName,
|
||||
productCode: item.productCode,
|
||||
color: item.color,
|
||||
meterage: item.meterage,
|
||||
unitPrice: item.unitPrice ?? undefined,
|
||||
notes: item.notes ?? undefined,
|
||||
companyId: item.companyId,
|
||||
companyName: item.companyName,
|
||||
})),
|
||||
totalMeterage: cart.items.reduce((s, i) => s + i.meterage, 0),
|
||||
itemCount: cart.items.length,
|
||||
createdAt: cart.createdAt.toISOString(),
|
||||
updatedAt: cart.updatedAt.toISOString(),
|
||||
};
|
||||
}
|
||||
};
|
||||
exports.CartsService = CartsService;
|
||||
exports.CartsService = CartsService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [prisma_service_1.PrismaService])
|
||||
], CartsService);
|
||||
//# sourceMappingURL=carts.service.js.map
|
||||
Vendored
+1
File diff suppressed because one or more lines are too long
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
export declare class AddCartItemDto {
|
||||
productId: string;
|
||||
meterage: number;
|
||||
notes?: string;
|
||||
}
|
||||
export declare class UpdateCartItemMeterageDto {
|
||||
meterage: number;
|
||||
notes?: string;
|
||||
}
|
||||
export declare class UpdateCartNotesDto {
|
||||
notes?: string;
|
||||
}
|
||||
Vendored
+61
@@ -0,0 +1,61 @@
|
||||
"use strict";
|
||||
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);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.UpdateCartNotesDto = exports.UpdateCartItemMeterageDto = exports.AddCartItemDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const class_transformer_1 = require("class-transformer");
|
||||
class AddCartItemDto {
|
||||
productId;
|
||||
meterage;
|
||||
notes;
|
||||
}
|
||||
exports.AddCartItemDto = AddCartItemDto;
|
||||
__decorate([
|
||||
(0, class_validator_1.IsString)(),
|
||||
__metadata("design:type", String)
|
||||
], AddCartItemDto.prototype, "productId", void 0);
|
||||
__decorate([
|
||||
(0, class_transformer_1.Type)(() => Number),
|
||||
(0, class_validator_1.IsNumber)(),
|
||||
(0, class_validator_1.Min)(0.001),
|
||||
__metadata("design:type", Number)
|
||||
], AddCartItemDto.prototype, "meterage", void 0);
|
||||
__decorate([
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
(0, class_validator_1.IsString)(),
|
||||
__metadata("design:type", String)
|
||||
], AddCartItemDto.prototype, "notes", void 0);
|
||||
class UpdateCartItemMeterageDto {
|
||||
meterage;
|
||||
notes;
|
||||
}
|
||||
exports.UpdateCartItemMeterageDto = UpdateCartItemMeterageDto;
|
||||
__decorate([
|
||||
(0, class_transformer_1.Type)(() => Number),
|
||||
(0, class_validator_1.IsNumber)(),
|
||||
(0, class_validator_1.Min)(0.001),
|
||||
__metadata("design:type", Number)
|
||||
], UpdateCartItemMeterageDto.prototype, "meterage", void 0);
|
||||
__decorate([
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
(0, class_validator_1.IsString)(),
|
||||
__metadata("design:type", String)
|
||||
], UpdateCartItemMeterageDto.prototype, "notes", void 0);
|
||||
class UpdateCartNotesDto {
|
||||
notes;
|
||||
}
|
||||
exports.UpdateCartNotesDto = UpdateCartNotesDto;
|
||||
__decorate([
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
(0, class_validator_1.IsString)(),
|
||||
__metadata("design:type", String)
|
||||
], UpdateCartNotesDto.prototype, "notes", void 0);
|
||||
//# sourceMappingURL=cart.dto.js.map
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"cart.dto.js","sourceRoot":"","sources":["../../../src/carts/dto/cart.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAsE;AACtE,yDAAyC;AAEzC,MAAa,cAAc;IAEzB,SAAS,CAAU;IAKnB,QAAQ,CAAU;IAIlB,KAAK,CAAU;CAChB;AAZD,wCAYC;AAVC;IADC,IAAA,0BAAQ,GAAE;;iDACQ;AAKnB;IAHC,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC;IAClB,IAAA,0BAAQ,GAAE;IACV,IAAA,qBAAG,EAAC,KAAK,CAAC;;gDACO;AAIlB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;6CACI;AAGjB,MAAa,yBAAyB;IAIpC,QAAQ,CAAU;IAIlB,KAAK,CAAU;CAChB;AATD,8DASC;AALC;IAHC,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC;IAClB,IAAA,0BAAQ,GAAE;IACV,IAAA,qBAAG,EAAC,KAAK,CAAC;;2DACO;AAIlB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;wDACI;AAGjB,MAAa,kBAAkB;IAG7B,KAAK,CAAU;CAChB;AAJD,gDAIC;AADC;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;iDACI"}
|
||||
Reference in New Issue
Block a user