diff --git a/.dockerignore b/.dockerignore index 26b13f7..dc4e863 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,4 @@ +node_modules coverage .git .gitignore @@ -11,3 +12,5 @@ test *.spec.ts .pgdata .tools +dist-docker +src diff --git a/.gitignore b/.gitignore index 9d1fc82..0da979d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ -# compiled output -/dist +# compiled output — dist را برای دیپلوی روی گیت می‌فرستیم +# /dist /dist-docker /node_modules /build diff --git a/Dockerfile.dist b/Dockerfile.dist new file mode 100644 index 0000000..2db923d --- /dev/null +++ b/Dockerfile.dist @@ -0,0 +1,32 @@ +# ایمیج اجرا: dist از گیت می‌آید، فقط dependencyهای production نصب می‌شود +ARG NPM_REGISTRY=https://registry.npmmirror.com + +FROM node:22-alpine +ARG NPM_REGISTRY=https://registry.npmmirror.com +WORKDIR /app + +ENV NODE_ENV=production +ENV NPM_CONFIG_REGISTRY=${NPM_REGISTRY} + +COPY package.json package-lock.json ./ +COPY prisma ./prisma +COPY prisma.config.ts ./ + +RUN set -eux; \ + mirror="$(echo "${NPM_REGISTRY}" | sed 's:/*$::')"; \ + sed -i \ + -e "s|https://registry.npmjs.org|${mirror}|g" \ + -e "s|https://registry.npmmirror.com|${mirror}|g" \ + package-lock.json; \ + npm config set registry "${mirror}"; \ + npm ci --omit=dev --no-audit --no-fund; \ + npm install prisma ts-node typescript --no-save --no-audit --no-fund --registry="${mirror}"; \ + npx prisma generate + +# بیلد لوکال که داخل گیت است +COPY dist ./dist +COPY docker-entrypoint.sh ./ +RUN chmod +x docker-entrypoint.sh + +EXPOSE 3000 +ENTRYPOINT ["./docker-entrypoint.sh"] diff --git a/dist/admin-users/admin-users.controller.d.ts b/dist/admin-users/admin-users.controller.d.ts new file mode 100644 index 0000000..0fd25cf --- /dev/null +++ b/dist/admin-users/admin-users.controller.d.ts @@ -0,0 +1,61 @@ +import { AdminUsersService } from './admin-users.service'; +import { CreateAdminUserDto, SetAdminActiveDto, UpdateAdminUserDto } from './dto/admin-user.dto'; +export declare class AdminUsersController { + private readonly adminUsersService; + constructor(adminUsersService: AdminUsersService); + findAll(): Promise<{ + id: string; + fullName: string; + phone: string; + email: string; + role: import("@prisma/client").$Enums.AdminRole; + isActive: boolean; + lastLoginAt: string | null; + createdAt: string; + updatedAt: string; + }[]>; + findOne(id: string): Promise<{ + id: string; + fullName: string; + phone: string; + email: string; + role: import("@prisma/client").$Enums.AdminRole; + isActive: boolean; + lastLoginAt: string | null; + createdAt: string; + updatedAt: string; + }>; + create(dto: CreateAdminUserDto): Promise<{ + id: string; + fullName: string; + phone: string; + email: string; + role: import("@prisma/client").$Enums.AdminRole; + isActive: boolean; + lastLoginAt: string | null; + createdAt: string; + updatedAt: string; + }>; + update(id: string, dto: UpdateAdminUserDto): Promise<{ + id: string; + fullName: string; + phone: string; + email: string; + role: import("@prisma/client").$Enums.AdminRole; + isActive: boolean; + lastLoginAt: string | null; + createdAt: string; + updatedAt: string; + }>; + setActive(id: string, dto: SetAdminActiveDto): Promise<{ + id: string; + fullName: string; + phone: string; + email: string; + role: import("@prisma/client").$Enums.AdminRole; + isActive: boolean; + lastLoginAt: string | null; + createdAt: string; + updatedAt: string; + }>; +} diff --git a/dist/admin-users/admin-users.controller.js b/dist/admin-users/admin-users.controller.js new file mode 100644 index 0000000..c91da3f --- /dev/null +++ b/dist/admin-users/admin-users.controller.js @@ -0,0 +1,83 @@ +"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.AdminUsersController = void 0; +const common_1 = require("@nestjs/common"); +const admin_users_service_1 = require("./admin-users.service"); +const auth_decorators_1 = require("../common/decorators/auth.decorators"); +const admin_user_dto_1 = require("./dto/admin-user.dto"); +let AdminUsersController = class AdminUsersController { + adminUsersService; + constructor(adminUsersService) { + this.adminUsersService = adminUsersService; + } + findAll() { + return this.adminUsersService.findAll(); + } + findOne(id) { + return this.adminUsersService.findOne(id); + } + create(dto) { + return this.adminUsersService.create(dto); + } + update(id, dto) { + return this.adminUsersService.update(id, dto); + } + setActive(id, dto) { + return this.adminUsersService.setActive(id, dto.isActive); + } +}; +exports.AdminUsersController = AdminUsersController; +__decorate([ + (0, common_1.Get)(), + __metadata("design:type", Function), + __metadata("design:paramtypes", []), + __metadata("design:returntype", void 0) +], AdminUsersController.prototype, "findAll", null); +__decorate([ + (0, common_1.Get)(':id'), + __param(0, (0, common_1.Param)('id')), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String]), + __metadata("design:returntype", void 0) +], AdminUsersController.prototype, "findOne", null); +__decorate([ + (0, common_1.Post)(), + __param(0, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [admin_user_dto_1.CreateAdminUserDto]), + __metadata("design:returntype", void 0) +], AdminUsersController.prototype, "create", null); +__decorate([ + (0, common_1.Patch)(':id'), + __param(0, (0, common_1.Param)('id')), + __param(1, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String, admin_user_dto_1.UpdateAdminUserDto]), + __metadata("design:returntype", void 0) +], AdminUsersController.prototype, "update", null); +__decorate([ + (0, common_1.Patch)(':id/active'), + __param(0, (0, common_1.Param)('id')), + __param(1, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String, admin_user_dto_1.SetAdminActiveDto]), + __metadata("design:returntype", void 0) +], AdminUsersController.prototype, "setActive", null); +exports.AdminUsersController = AdminUsersController = __decorate([ + (0, common_1.Controller)('admin/users'), + (0, auth_decorators_1.AuthType)('admin'), + __metadata("design:paramtypes", [admin_users_service_1.AdminUsersService]) +], AdminUsersController); +//# sourceMappingURL=admin-users.controller.js.map \ No newline at end of file diff --git a/dist/admin-users/admin-users.controller.js.map b/dist/admin-users/admin-users.controller.js.map new file mode 100644 index 0000000..804b6ab --- /dev/null +++ b/dist/admin-users/admin-users.controller.js.map @@ -0,0 +1 @@ +{"version":3,"file":"admin-users.controller.js","sourceRoot":"","sources":["../../src/admin-users/admin-users.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA2E;AAC3E,+DAA0D;AAC1D,0EAAgE;AAChE,yDAI8B;AAIvB,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IACF;IAA7B,YAA6B,iBAAoC;QAApC,sBAAiB,GAAjB,iBAAiB,CAAmB;IAAG,CAAC;IAGrE,OAAO;QACL,OAAO,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,CAAC;IAC1C,CAAC;IAGD,OAAO,CAAc,EAAU;QAC7B,OAAO,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC5C,CAAC;IAGD,MAAM,CAAS,GAAuB;QACpC,OAAO,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC5C,CAAC;IAGD,MAAM,CAAc,EAAU,EAAU,GAAuB;QAC7D,OAAO,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IAChD,CAAC;IAGD,SAAS,CAAc,EAAU,EAAU,GAAsB;QAC/D,OAAO,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,EAAE,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC5D,CAAC;CACF,CAAA;AA3BY,oDAAoB;AAI/B;IADC,IAAA,YAAG,GAAE;;;;mDAGL;AAGD;IADC,IAAA,YAAG,EAAC,KAAK,CAAC;IACF,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;;;;mDAEnB;AAGD;IADC,IAAA,aAAI,GAAE;IACC,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAM,mCAAkB;;kDAErC;AAGD;IADC,IAAA,cAAK,EAAC,KAAK,CAAC;IACL,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;IAAc,WAAA,IAAA,aAAI,GAAE,CAAA;;6CAAM,mCAAkB;;kDAE9D;AAGD;IADC,IAAA,cAAK,EAAC,YAAY,CAAC;IACT,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;IAAc,WAAA,IAAA,aAAI,GAAE,CAAA;;6CAAM,kCAAiB;;qDAEhE;+BA1BU,oBAAoB;IAFhC,IAAA,mBAAU,EAAC,aAAa,CAAC;IACzB,IAAA,0BAAQ,EAAC,OAAO,CAAC;qCAEgC,uCAAiB;GADtD,oBAAoB,CA2BhC"} \ No newline at end of file diff --git a/dist/admin-users/admin-users.module.d.ts b/dist/admin-users/admin-users.module.d.ts new file mode 100644 index 0000000..6f882f8 --- /dev/null +++ b/dist/admin-users/admin-users.module.d.ts @@ -0,0 +1,2 @@ +export declare class AdminUsersModule { +} diff --git a/dist/admin-users/admin-users.module.js b/dist/admin-users/admin-users.module.js new file mode 100644 index 0000000..a33709e --- /dev/null +++ b/dist/admin-users/admin-users.module.js @@ -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.AdminUsersModule = void 0; +const common_1 = require("@nestjs/common"); +const admin_users_controller_1 = require("./admin-users.controller"); +const admin_users_service_1 = require("./admin-users.service"); +let AdminUsersModule = class AdminUsersModule { +}; +exports.AdminUsersModule = AdminUsersModule; +exports.AdminUsersModule = AdminUsersModule = __decorate([ + (0, common_1.Module)({ + controllers: [admin_users_controller_1.AdminUsersController], + providers: [admin_users_service_1.AdminUsersService], + exports: [admin_users_service_1.AdminUsersService], + }) +], AdminUsersModule); +//# sourceMappingURL=admin-users.module.js.map \ No newline at end of file diff --git a/dist/admin-users/admin-users.module.js.map b/dist/admin-users/admin-users.module.js.map new file mode 100644 index 0000000..32c10fc --- /dev/null +++ b/dist/admin-users/admin-users.module.js.map @@ -0,0 +1 @@ +{"version":3,"file":"admin-users.module.js","sourceRoot":"","sources":["../../src/admin-users/admin-users.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,qEAAgE;AAChE,+DAA0D;AAOnD,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;CAAG,CAAA;AAAnB,4CAAgB;2BAAhB,gBAAgB;IAL5B,IAAA,eAAM,EAAC;QACN,WAAW,EAAE,CAAC,6CAAoB,CAAC;QACnC,SAAS,EAAE,CAAC,uCAAiB,CAAC;QAC9B,OAAO,EAAE,CAAC,uCAAiB,CAAC;KAC7B,CAAC;GACW,gBAAgB,CAAG"} \ No newline at end of file diff --git a/dist/admin-users/admin-users.service.d.ts b/dist/admin-users/admin-users.service.d.ts new file mode 100644 index 0000000..dfeedf5 --- /dev/null +++ b/dist/admin-users/admin-users.service.d.ts @@ -0,0 +1,63 @@ +import { PrismaService } from '../prisma/prisma.service'; +import { CreateAdminUserDto, UpdateAdminUserDto } from './dto/admin-user.dto'; +export declare class AdminUsersService { + private readonly prisma; + constructor(prisma: PrismaService); + findAll(): Promise<{ + id: string; + fullName: string; + phone: string; + email: string; + role: import("@prisma/client").$Enums.AdminRole; + isActive: boolean; + lastLoginAt: string | null; + createdAt: string; + updatedAt: string; + }[]>; + findOne(id: string): Promise<{ + id: string; + fullName: string; + phone: string; + email: string; + role: import("@prisma/client").$Enums.AdminRole; + isActive: boolean; + lastLoginAt: string | null; + createdAt: string; + updatedAt: string; + }>; + create(dto: CreateAdminUserDto): Promise<{ + id: string; + fullName: string; + phone: string; + email: string; + role: import("@prisma/client").$Enums.AdminRole; + isActive: boolean; + lastLoginAt: string | null; + createdAt: string; + updatedAt: string; + }>; + update(id: string, dto: UpdateAdminUserDto): Promise<{ + id: string; + fullName: string; + phone: string; + email: string; + role: import("@prisma/client").$Enums.AdminRole; + isActive: boolean; + lastLoginAt: string | null; + createdAt: string; + updatedAt: string; + }>; + setActive(id: string, isActive: boolean): Promise<{ + id: string; + fullName: string; + phone: string; + email: string; + role: import("@prisma/client").$Enums.AdminRole; + isActive: boolean; + lastLoginAt: string | null; + createdAt: string; + updatedAt: string; + }>; + private ensure; + private map; +} diff --git a/dist/admin-users/admin-users.service.js b/dist/admin-users/admin-users.service.js new file mode 100644 index 0000000..37e3fc9 --- /dev/null +++ b/dist/admin-users/admin-users.service.js @@ -0,0 +1,160 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +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 __importStar = (this && this.__importStar) || (function () { + var ownKeys = function(o) { + ownKeys = Object.getOwnPropertyNames || function (o) { + var ar = []; + for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; + return ar; + }; + return ownKeys(o); + }; + return function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); + __setModuleDefault(result, mod); + return result; + }; +})(); +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.AdminUsersService = void 0; +const common_1 = require("@nestjs/common"); +const client_1 = require("@prisma/client"); +const bcrypt = __importStar(require("bcryptjs")); +const prisma_service_1 = require("../prisma/prisma.service"); +const phone_1 = require("../common/utils/phone"); +const DEFAULT_PASSWORD = 'admin123'; +let AdminUsersService = class AdminUsersService { + prisma; + constructor(prisma) { + this.prisma = prisma; + } + async findAll() { + const users = await this.prisma.adminUser.findMany({ + orderBy: { createdAt: 'desc' }, + }); + return users.map((u) => this.map(u)); + } + async findOne(id) { + const user = await this.prisma.adminUser.findUnique({ where: { id } }); + if (!user) + throw new common_1.NotFoundException('کاربر ادمین یافت نشد'); + return this.map(user); + } + async create(dto) { + const phone = (0, phone_1.normalizePhone)((0, phone_1.toEnglishDigits)(dto.phone)); + if (!(0, phone_1.isValidPhone)(phone)) { + throw new common_1.BadRequestException('شماره موبایل نامعتبر است'); + } + const passwordHash = await bcrypt.hash(dto.password?.trim() || DEFAULT_PASSWORD, 10); + try { + const user = await this.prisma.adminUser.create({ + data: { + fullName: dto.fullName.trim(), + phone, + email: dto.email.trim().toLowerCase(), + passwordHash, + role: dto.role ?? client_1.AdminRole.admin, + isActive: dto.isActive ?? true, + }, + }); + return this.map(user); + } + catch (e) { + if (e instanceof client_1.Prisma.PrismaClientKnownRequestError && e.code === 'P2002') { + throw new common_1.ConflictException('شماره یا ایمیل تکراری است'); + } + throw e; + } + } + async update(id, dto) { + await this.ensure(id); + const phone = dto.phone !== undefined + ? (0, phone_1.normalizePhone)((0, phone_1.toEnglishDigits)(dto.phone)) + : undefined; + if (phone !== undefined && !(0, phone_1.isValidPhone)(phone)) { + throw new common_1.BadRequestException('شماره موبایل نامعتبر است'); + } + const data = { + fullName: dto.fullName?.trim(), + phone, + email: dto.email?.trim().toLowerCase(), + role: dto.role, + isActive: dto.isActive, + }; + if (dto.password?.trim()) { + data.passwordHash = await bcrypt.hash(dto.password.trim(), 10); + } + try { + const user = await this.prisma.adminUser.update({ + where: { id }, + data, + }); + return this.map(user); + } + catch (e) { + if (e instanceof client_1.Prisma.PrismaClientKnownRequestError && e.code === 'P2002') { + throw new common_1.ConflictException('شماره یا ایمیل تکراری است'); + } + throw e; + } + } + async setActive(id, isActive) { + await this.ensure(id); + const user = await this.prisma.adminUser.update({ + where: { id }, + data: { isActive }, + }); + return this.map(user); + } + async ensure(id) { + const user = await this.prisma.adminUser.findUnique({ where: { id } }); + if (!user) + throw new common_1.NotFoundException('کاربر ادمین یافت نشد'); + return user; + } + map(user) { + return { + id: user.id, + fullName: user.fullName, + phone: user.phone, + email: user.email, + role: user.role, + isActive: user.isActive, + lastLoginAt: user.lastLoginAt?.toISOString() ?? null, + createdAt: user.createdAt.toISOString(), + updatedAt: user.updatedAt.toISOString(), + }; + } +}; +exports.AdminUsersService = AdminUsersService; +exports.AdminUsersService = AdminUsersService = __decorate([ + (0, common_1.Injectable)(), + __metadata("design:paramtypes", [prisma_service_1.PrismaService]) +], AdminUsersService); +//# sourceMappingURL=admin-users.service.js.map \ No newline at end of file diff --git a/dist/admin-users/admin-users.service.js.map b/dist/admin-users/admin-users.service.js.map new file mode 100644 index 0000000..8c9f99d --- /dev/null +++ b/dist/admin-users/admin-users.service.js.map @@ -0,0 +1 @@ +{"version":3,"file":"admin-users.service.js","sourceRoot":"","sources":["../../src/admin-users/admin-users.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAKwB;AACxB,2CAAmD;AACnD,iDAAmC;AACnC,6DAAyD;AAEzD,iDAI+B;AAE/B,MAAM,gBAAgB,GAAG,UAAU,CAAC;AAG7B,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IACC;IAA7B,YAA6B,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;IAEtD,KAAK,CAAC,OAAO;QACX,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC;YACjD,OAAO,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE;SAC/B,CAAC,CAAC;QACH,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,EAAU;QACtB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;QACvE,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,0BAAiB,CAAC,sBAAsB,CAAC,CAAC;QAC/D,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAuB;QAClC,MAAM,KAAK,GAAG,IAAA,sBAAc,EAAC,IAAA,uBAAe,EAAC,GAAG,CA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,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC;YAC9C,KAAK,EAAE,EAAE,EAAE,EAAE;YACb,IAAI,EAAE,EAAE,QAAQ,EAAE;SACnB,CAAC,CAAC;QACH,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAEO,KAAK,CAAC,MAAM,CAAC,EAAU;QAC7B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;QACvE,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,0BAAiB,CAAC,sBAAsB,CAAC,CAAC;QAC/D,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,GAAG,CAAC,IAUX;QACC,OAAO;YACL,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,WAAW,EAAE,IAAI,IAAI;YACpD,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE;YACvC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE;SACxC,CAAC;IACJ,CAAC;CACF,CAAA;AAvHY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;qCAE0B,8BAAa;GADvC,iBAAiB,CAuH7B"} \ No newline at end of file diff --git a/dist/admin-users/dto/admin-user.dto.d.ts b/dist/admin-users/dto/admin-user.dto.d.ts new file mode 100644 index 0000000..4608a36 --- /dev/null +++ b/dist/admin-users/dto/admin-user.dto.d.ts @@ -0,0 +1,20 @@ +import { AdminRole } from '@prisma/client'; +export declare class CreateAdminUserDto { + fullName: string; + phone: string; + email: string; + password?: string; + role?: AdminRole; + isActive?: boolean; +} +export declare class UpdateAdminUserDto { + fullName?: string; + phone?: string; + email?: string; + password?: string; + role?: AdminRole; + isActive?: boolean; +} +export declare class SetAdminActiveDto { + isActive: boolean; +} diff --git a/dist/admin-users/dto/admin-user.dto.js b/dist/admin-users/dto/admin-user.dto.js new file mode 100644 index 0000000..2a8167f --- /dev/null +++ b/dist/admin-users/dto/admin-user.dto.js @@ -0,0 +1,103 @@ +"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.SetAdminActiveDto = exports.UpdateAdminUserDto = exports.CreateAdminUserDto = void 0; +const class_validator_1 = require("class-validator"); +const client_1 = require("@prisma/client"); +class CreateAdminUserDto { + fullName; + phone; + email; + password; + role; + isActive; +} +exports.CreateAdminUserDto = CreateAdminUserDto; +__decorate([ + (0, class_validator_1.IsString)(), + (0, class_validator_1.MinLength)(1), + __metadata("design:type", String) +], CreateAdminUserDto.prototype, "fullName", void 0); +__decorate([ + (0, class_validator_1.IsString)(), + (0, class_validator_1.MinLength)(10), + __metadata("design:type", String) +], CreateAdminUserDto.prototype, "phone", void 0); +__decorate([ + (0, class_validator_1.IsEmail)(), + __metadata("design:type", String) +], CreateAdminUserDto.prototype, "email", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + (0, class_validator_1.MinLength)(4), + __metadata("design:type", String) +], CreateAdminUserDto.prototype, "password", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsEnum)(client_1.AdminRole), + __metadata("design:type", String) +], CreateAdminUserDto.prototype, "role", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsBoolean)(), + __metadata("design:type", Boolean) +], CreateAdminUserDto.prototype, "isActive", void 0); +class UpdateAdminUserDto { + fullName; + phone; + email; + password; + role; + isActive; +} +exports.UpdateAdminUserDto = UpdateAdminUserDto; +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + (0, class_validator_1.MinLength)(1), + __metadata("design:type", String) +], UpdateAdminUserDto.prototype, "fullName", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], UpdateAdminUserDto.prototype, "phone", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsEmail)(), + __metadata("design:type", String) +], UpdateAdminUserDto.prototype, "email", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + (0, class_validator_1.MinLength)(4), + __metadata("design:type", String) +], UpdateAdminUserDto.prototype, "password", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsEnum)(client_1.AdminRole), + __metadata("design:type", String) +], UpdateAdminUserDto.prototype, "role", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsBoolean)(), + __metadata("design:type", Boolean) +], UpdateAdminUserDto.prototype, "isActive", void 0); +class SetAdminActiveDto { + isActive; +} +exports.SetAdminActiveDto = SetAdminActiveDto; +__decorate([ + (0, class_validator_1.IsBoolean)(), + __metadata("design:type", Boolean) +], SetAdminActiveDto.prototype, "isActive", void 0); +//# sourceMappingURL=admin-user.dto.js.map \ No newline at end of file diff --git a/dist/admin-users/dto/admin-user.dto.js.map b/dist/admin-users/dto/admin-user.dto.js.map new file mode 100644 index 0000000..ebc9b3d --- /dev/null +++ b/dist/admin-users/dto/admin-user.dto.js.map @@ -0,0 +1 @@ +{"version":3,"file":"admin-user.dto.js","sourceRoot":"","sources":["../../../src/admin-users/dto/admin-user.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAOyB;AACzB,2CAA2C;AAE3C,MAAa,kBAAkB;IAG7B,QAAQ,CAAU;IAIlB,KAAK,CAAU;IAGf,KAAK,CAAU;IAKf,QAAQ,CAAU;IAIlB,IAAI,CAAa;IAIjB,QAAQ,CAAW;CACpB;AAxBD,gDAwBC;AArBC;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,2BAAS,EAAC,CAAC,CAAC;;oDACK;AAIlB;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,2BAAS,EAAC,EAAE,CAAC;;iDACC;AAGf;IADC,IAAA,yBAAO,GAAE;;iDACK;AAKf;IAHC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;IACV,IAAA,2BAAS,EAAC,CAAC,CAAC;;oDACK;AAIlB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,wBAAM,EAAC,kBAAS,CAAC;;gDACD;AAIjB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,2BAAS,GAAE;;oDACO;AAGrB,MAAa,kBAAkB;IAI7B,QAAQ,CAAU;IAIlB,KAAK,CAAU;IAIf,KAAK,CAAU;IAKf,QAAQ,CAAU;IAIlB,IAAI,CAAa;IAIjB,QAAQ,CAAW;CACpB;AA1BD,gDA0BC;AAtBC;IAHC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;IACV,IAAA,2BAAS,EAAC,CAAC,CAAC;;oDACK;AAIlB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;iDACI;AAIf;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,yBAAO,GAAE;;iDACK;AAKf;IAHC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;IACV,IAAA,2BAAS,EAAC,CAAC,CAAC;;oDACK;AAIlB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,wBAAM,EAAC,kBAAS,CAAC;;gDACD;AAIjB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,2BAAS,GAAE;;oDACO;AAGrB,MAAa,iBAAiB;IAE5B,QAAQ,CAAW;CACpB;AAHD,8CAGC;AADC;IADC,IAAA,2BAAS,GAAE;;mDACO"} \ No newline at end of file diff --git a/dist/app.module.d.ts b/dist/app.module.d.ts new file mode 100644 index 0000000..09cdb35 --- /dev/null +++ b/dist/app.module.d.ts @@ -0,0 +1,2 @@ +export declare class AppModule { +} diff --git a/dist/app.module.js b/dist/app.module.js new file mode 100644 index 0000000..69ab9de --- /dev/null +++ b/dist/app.module.js @@ -0,0 +1,58 @@ +"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.AppModule = void 0; +const common_1 = require("@nestjs/common"); +const core_1 = require("@nestjs/core"); +const config_1 = require("@nestjs/config"); +const prisma_module_1 = require("./prisma/prisma.module"); +const auth_module_1 = require("./auth/auth.module"); +const jwt_auth_guard_1 = require("./common/guards/jwt-auth.guard"); +const companies_module_1 = require("./companies/companies.module"); +const catalogs_module_1 = require("./catalogs/catalogs.module"); +const products_module_1 = require("./products/products.module"); +const customers_module_1 = require("./customers/customers.module"); +const admin_users_module_1 = require("./admin-users/admin-users.module"); +const orders_module_1 = require("./orders/orders.module"); +const checks_module_1 = require("./checks/checks.module"); +const cash_payments_module_1 = require("./cash-payments/cash-payments.module"); +const shipments_module_1 = require("./shipments/shipments.module"); +const dashboard_module_1 = require("./dashboard/dashboard.module"); +const settings_module_1 = require("./settings/settings.module"); +const carts_module_1 = require("./carts/carts.module"); +let AppModule = class AppModule { +}; +exports.AppModule = AppModule; +exports.AppModule = AppModule = __decorate([ + (0, common_1.Module)({ + imports: [ + config_1.ConfigModule.forRoot({ isGlobal: true }), + prisma_module_1.PrismaModule, + auth_module_1.AuthModule, + companies_module_1.CompaniesModule, + catalogs_module_1.CatalogsModule, + products_module_1.ProductsModule, + customers_module_1.CustomersModule, + admin_users_module_1.AdminUsersModule, + orders_module_1.OrdersModule, + checks_module_1.ChecksModule, + cash_payments_module_1.CashPaymentsModule, + shipments_module_1.ShipmentsModule, + dashboard_module_1.DashboardModule, + settings_module_1.SettingsModule, + carts_module_1.CartsModule, + ], + providers: [ + { + provide: core_1.APP_GUARD, + useClass: jwt_auth_guard_1.JwtAuthGuard, + }, + ], + }) +], AppModule); +//# sourceMappingURL=app.module.js.map \ No newline at end of file diff --git a/dist/app.module.js.map b/dist/app.module.js.map new file mode 100644 index 0000000..e4d7779 --- /dev/null +++ b/dist/app.module.js.map @@ -0,0 +1 @@ +{"version":3,"file":"app.module.js","sourceRoot":"","sources":["../src/app.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,uCAAyC;AACzC,2CAA8C;AAC9C,0DAAsD;AACtD,oDAAgD;AAChD,mEAA8D;AAC9D,mEAA+D;AAC/D,gEAA4D;AAC5D,gEAA4D;AAC5D,mEAA+D;AAC/D,yEAAoE;AACpE,0DAAsD;AACtD,0DAAsD;AACtD,+EAA0E;AAC1E,mEAA+D;AAC/D,mEAA+D;AAC/D,gEAA4D;AAC5D,uDAAmD;AA2B5C,IAAM,SAAS,GAAf,MAAM,SAAS;CAAG,CAAA;AAAZ,8BAAS;oBAAT,SAAS;IAzBrB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,qBAAY,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;YACxC,4BAAY;YACZ,wBAAU;YACV,kCAAe;YACf,gCAAc;YACd,gCAAc;YACd,kCAAe;YACf,qCAAgB;YAChB,4BAAY;YACZ,4BAAY;YACZ,yCAAkB;YAClB,kCAAe;YACf,kCAAe;YACf,gCAAc;YACd,0BAAW;SACZ;QACD,SAAS,EAAE;YACT;gBACE,OAAO,EAAE,gBAAS;gBAClB,QAAQ,EAAE,6BAAY;aACvB;SACF;KACF,CAAC;GACW,SAAS,CAAG"} \ No newline at end of file diff --git a/dist/auth/auth.controller.d.ts b/dist/auth/auth.controller.d.ts new file mode 100644 index 0000000..8e48e79 --- /dev/null +++ b/dist/auth/auth.controller.d.ts @@ -0,0 +1,60 @@ +import { AuthService } from './auth.service'; +import { AdminLoginDto, RequestOtpDto, UpdateProfileDto, VerifyOtpDto } from './dto/auth.dto'; +import type { AuthPrincipal } from '../common/decorators/current-user.decorator'; +export declare class AuthController { + private readonly authService; + constructor(authService: AuthService); + health(): { + ok: boolean; + service: string; + }; + requestOtp(dto: RequestOtpDto): Promise<{ + success: boolean; + message: string; + expiresAt: Date; + debugCode: string; + }>; + verifyOtp(dto: VerifyOtpDto): Promise<{ + accessToken: string; + user: { + id: string; + firstName: string; + lastName: string; + phone: string; + nationalId: string | undefined; + createdAt: string; + }; + }>; + adminLogin(dto: AdminLoginDto): Promise<{ + accessToken: string; + user: { + id: string; + fullName: string; + phone: string; + email: string; + role: import("@prisma/client").$Enums.AdminRole; + }; + }>; + me(user: AuthPrincipal): Promise<{ + id: string; + firstName: string; + lastName: string; + phone: string; + nationalId: string | undefined; + createdAt: string; + } | { + id: string; + fullName: string; + phone: string; + email: string; + role: import("@prisma/client").$Enums.AdminRole; + }>; + updateProfile(user: AuthPrincipal, dto: UpdateProfileDto): Promise<{ + id: string; + firstName: string; + lastName: string; + phone: string; + nationalId: string | undefined; + createdAt: string; + }>; +} diff --git a/dist/auth/auth.controller.js b/dist/auth/auth.controller.js new file mode 100644 index 0000000..aa5256d --- /dev/null +++ b/dist/auth/auth.controller.js @@ -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.AuthController = void 0; +const common_1 = require("@nestjs/common"); +const auth_service_1 = require("./auth.service"); +const auth_dto_1 = require("./dto/auth.dto"); +const auth_decorators_1 = require("../common/decorators/auth.decorators"); +const current_user_decorator_1 = require("../common/decorators/current-user.decorator"); +let AuthController = class AuthController { + authService; + constructor(authService) { + this.authService = authService; + } + health() { + return { ok: true, service: 'fabric-trade-api' }; + } + requestOtp(dto) { + return this.authService.requestOtp(dto); + } + verifyOtp(dto) { + return this.authService.verifyOtp(dto); + } + adminLogin(dto) { + return this.authService.adminLogin(dto); + } + me(user) { + return this.authService.me(user.id, user.type); + } + updateProfile(user, dto) { + return this.authService.updateProfile(user.id, dto); + } +}; +exports.AuthController = AuthController; +__decorate([ + (0, auth_decorators_1.Public)(), + (0, common_1.Get)('health'), + __metadata("design:type", Function), + __metadata("design:paramtypes", []), + __metadata("design:returntype", void 0) +], AuthController.prototype, "health", null); +__decorate([ + (0, auth_decorators_1.Public)(), + (0, common_1.Post)('auth/otp/request'), + __param(0, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [auth_dto_1.RequestOtpDto]), + __metadata("design:returntype", void 0) +], AuthController.prototype, "requestOtp", null); +__decorate([ + (0, auth_decorators_1.Public)(), + (0, common_1.Post)('auth/otp/verify'), + __param(0, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [auth_dto_1.VerifyOtpDto]), + __metadata("design:returntype", void 0) +], AuthController.prototype, "verifyOtp", null); +__decorate([ + (0, auth_decorators_1.Public)(), + (0, common_1.Post)('admin/auth/login'), + __param(0, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [auth_dto_1.AdminLoginDto]), + __metadata("design:returntype", void 0) +], AuthController.prototype, "adminLogin", null); +__decorate([ + (0, auth_decorators_1.AuthType)('any'), + (0, common_1.Get)('auth/me'), + __param(0, (0, current_user_decorator_1.CurrentUser)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [Object]), + __metadata("design:returntype", void 0) +], AuthController.prototype, "me", null); +__decorate([ + (0, auth_decorators_1.AuthType)('customer'), + (0, common_1.Patch)('auth/profile'), + __param(0, (0, current_user_decorator_1.CurrentUser)()), + __param(1, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [Object, auth_dto_1.UpdateProfileDto]), + __metadata("design:returntype", void 0) +], AuthController.prototype, "updateProfile", null); +exports.AuthController = AuthController = __decorate([ + (0, common_1.Controller)(), + __metadata("design:paramtypes", [auth_service_1.AuthService]) +], AuthController); +//# sourceMappingURL=auth.controller.js.map \ No newline at end of file diff --git a/dist/auth/auth.controller.js.map b/dist/auth/auth.controller.js.map new file mode 100644 index 0000000..ffd49d5 --- /dev/null +++ b/dist/auth/auth.controller.js.map @@ -0,0 +1 @@ +{"version":3,"file":"auth.controller.js","sourceRoot":"","sources":["../../src/auth/auth.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoE;AACpE,iDAA6C;AA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IAAA,aAAI,EAAC,kBAAkB,CAAC;IACb,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAM,wBAAa;;gDAEpC;AAID;IAFC,IAAA,0BAAQ,EAAC,KAAK,CAAC;IACf,IAAA,YAAG,EAAC,SAAS,CAAC;IACX,WAAA,IAAA,oCAAW,GAAE,CAAA;;;;wCAEhB;AAID;IAFC,IAAA,0BAAQ,EAAC,UAAU,CAAC;IACpB,IAAA,cAAK,EAAC,cAAc,CAAC;IAEnB,WAAA,IAAA,oCAAW,GAAE,CAAA;IACb,WAAA,IAAA,aAAI,GAAE,CAAA;;6CAAM,2BAAgB;;mDAG9B;yBAxCU,cAAc;IAD1B,IAAA,mBAAU,GAAE;qCAE+B,0BAAW;GAD1C,cAAc,CAyC1B"} \ No newline at end of file diff --git a/dist/auth/auth.module.d.ts b/dist/auth/auth.module.d.ts new file mode 100644 index 0000000..3f7dba9 --- /dev/null +++ b/dist/auth/auth.module.d.ts @@ -0,0 +1,2 @@ +export declare class AuthModule { +} diff --git a/dist/auth/auth.module.js b/dist/auth/auth.module.js new file mode 100644 index 0000000..5eea5ed --- /dev/null +++ b/dist/auth/auth.module.js @@ -0,0 +1,37 @@ +"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.AuthModule = void 0; +const common_1 = require("@nestjs/common"); +const jwt_1 = require("@nestjs/jwt"); +const config_1 = require("@nestjs/config"); +const auth_service_1 = require("./auth.service"); +const auth_controller_1 = require("./auth.controller"); +let AuthModule = class AuthModule { +}; +exports.AuthModule = AuthModule; +exports.AuthModule = AuthModule = __decorate([ + (0, common_1.Module)({ + imports: [ + jwt_1.JwtModule.registerAsync({ + imports: [config_1.ConfigModule], + inject: [config_1.ConfigService], + useFactory: (config) => ({ + secret: config.get('JWT_SECRET', 'fabric-trade-dev-secret'), + signOptions: { + expiresIn: config.get('JWT_EXPIRES_IN', '7d'), + }, + }), + }), + ], + controllers: [auth_controller_1.AuthController], + providers: [auth_service_1.AuthService], + exports: [auth_service_1.AuthService, jwt_1.JwtModule], + }) +], AuthModule); +//# sourceMappingURL=auth.module.js.map \ No newline at end of file diff --git a/dist/auth/auth.module.js.map b/dist/auth/auth.module.js.map new file mode 100644 index 0000000..7445f9b --- /dev/null +++ b/dist/auth/auth.module.js.map @@ -0,0 +1 @@ +{"version":3,"file":"auth.module.js","sourceRoot":"","sources":["../../src/auth/auth.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,qCAAwC;AACxC,2CAA6D;AAC7D,iDAA6C;AAC7C,uDAAmD;AAmB5C,IAAM,UAAU,GAAhB,MAAM,UAAU;CAAG,CAAA;AAAb,gCAAU;qBAAV,UAAU;IAjBtB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,eAAS,CAAC,aAAa,CAAC;gBACtB,OAAO,EAAE,CAAC,qBAAY,CAAC;gBACvB,MAAM,EAAE,CAAC,sBAAa,CAAC;gBACvB,UAAU,EAAE,CAAC,MAAqB,EAAE,EAAE,CAAC,CAAC;oBACtC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAS,YAAY,EAAE,yBAAyB,CAAC;oBACnE,WAAW,EAAE;wBACX,SAAS,EAAE,MAAM,CAAC,GAAG,CAAC,gBAAgB,EAAE,IAAI,CAAiB;qBAC9D;iBACF,CAAC;aACH,CAAC;SACH;QACD,WAAW,EAAE,CAAC,gCAAc,CAAC;QAC7B,SAAS,EAAE,CAAC,0BAAW,CAAC;QACxB,OAAO,EAAE,CAAC,0BAAW,EAAE,eAAS,CAAC;KAClC,CAAC;GACW,UAAU,CAAG"} \ No newline at end of file diff --git a/dist/auth/auth.service.d.ts b/dist/auth/auth.service.d.ts new file mode 100644 index 0000000..ab1dbac --- /dev/null +++ b/dist/auth/auth.service.d.ts @@ -0,0 +1,61 @@ +import { ConfigService } from '@nestjs/config'; +import { JwtService } from '@nestjs/jwt'; +import { PrismaService } from '../prisma/prisma.service'; +import { AdminLoginDto, RequestOtpDto, UpdateProfileDto, VerifyOtpDto } from './dto/auth.dto'; +export declare class AuthService { + private readonly prisma; + private readonly jwt; + private readonly config; + constructor(prisma: PrismaService, jwt: JwtService, config: ConfigService); + requestOtp(dto: RequestOtpDto): Promise<{ + success: boolean; + message: string; + expiresAt: Date; + debugCode: string; + }>; + verifyOtp(dto: VerifyOtpDto): Promise<{ + accessToken: string; + user: { + id: string; + firstName: string; + lastName: string; + phone: string; + nationalId: string | undefined; + createdAt: string; + }; + }>; + adminLogin(dto: AdminLoginDto): Promise<{ + accessToken: string; + user: { + id: string; + fullName: string; + phone: string; + email: string; + role: import("@prisma/client").$Enums.AdminRole; + }; + }>; + me(userId: string, type: 'customer' | 'admin'): Promise<{ + id: string; + firstName: string; + lastName: string; + phone: string; + nationalId: string | undefined; + createdAt: string; + } | { + id: string; + fullName: string; + phone: string; + email: string; + role: import("@prisma/client").$Enums.AdminRole; + }>; + updateProfile(userId: string, dto: UpdateProfileDto): Promise<{ + id: string; + firstName: string; + lastName: string; + phone: string; + nationalId: string | undefined; + createdAt: string; + }>; + private signCustomerToken; + private mapCustomer; +} diff --git a/dist/auth/auth.service.js b/dist/auth/auth.service.js new file mode 100644 index 0000000..09ab890 --- /dev/null +++ b/dist/auth/auth.service.js @@ -0,0 +1,221 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +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 __importStar = (this && this.__importStar) || (function () { + var ownKeys = function(o) { + ownKeys = Object.getOwnPropertyNames || function (o) { + var ar = []; + for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; + return ar; + }; + return ownKeys(o); + }; + return function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); + __setModuleDefault(result, mod); + return result; + }; +})(); +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.AuthService = void 0; +const common_1 = require("@nestjs/common"); +const config_1 = require("@nestjs/config"); +const jwt_1 = require("@nestjs/jwt"); +const bcrypt = __importStar(require("bcryptjs")); +const prisma_service_1 = require("../prisma/prisma.service"); +const phone_1 = require("../common/utils/phone"); +let AuthService = class AuthService { + prisma; + jwt; + config; + constructor(prisma, jwt, config) { + this.prisma = prisma; + this.jwt = jwt; + this.config = config; + } + async requestOtp(dto) { + const phone = (0, phone_1.normalizePhone)((0, phone_1.toEnglishDigits)(dto.phone)); + if (!(0, phone_1.isValidPhone)(phone)) { + throw new common_1.BadRequestException('شماره موبایل نامعتبر است'); + } + const existing = await this.prisma.customer.findUnique({ where: { phone } }); + const isRegister = Boolean(dto.isRegister); + if (isRegister) { + if (!dto.firstName?.trim() || !dto.lastName?.trim()) { + throw new common_1.BadRequestException('نام و نام خانوادگی الزامی است'); + } + if (existing) { + throw new common_1.BadRequestException('این شماره قبلاً ثبت شده است'); + } + } + else if (!existing) { + throw new common_1.BadRequestException('کاربری با این شماره یافت نشد'); + } + const code = this.config.get('MOCK_OTP_CODE', '123456'); + const ttl = Number(this.config.get('OTP_TTL_MINUTES', 5)); + const expiresAt = new Date(Date.now() + ttl * 60_000); + await this.prisma.otpChallenge.deleteMany({ where: { phone } }); + await this.prisma.otpChallenge.create({ + data: { + phone, + code, + firstName: dto.firstName?.trim(), + lastName: dto.lastName?.trim(), + isRegister, + expiresAt, + }, + }); + return { + success: true, + message: 'کد تأیید ارسال شد', + expiresAt, + debugCode: code, + }; + } + async verifyOtp(dto) { + const phone = (0, phone_1.normalizePhone)((0, phone_1.toEnglishDigits)(dto.phone)); + const code = (0, phone_1.toEnglishDigits)(dto.code).trim(); + const challenge = await this.prisma.otpChallenge.findFirst({ + where: { phone }, + orderBy: { createdAt: 'desc' }, + }); + if (!challenge || challenge.expiresAt < new Date()) { + throw new common_1.UnauthorizedException('کد منقضی شده است'); + } + if (challenge.code !== code) { + throw new common_1.UnauthorizedException('کد تأیید نادرست است'); + } + let user = await this.prisma.customer.findUnique({ where: { phone } }); + if (challenge.isRegister) { + if (user) { + throw new common_1.BadRequestException('این شماره قبلاً ثبت شده است'); + } + user = await this.prisma.customer.create({ + data: { + phone, + firstName: challenge.firstName ?? 'کاربر', + lastName: challenge.lastName ?? 'جدید', + }, + }); + } + else if (!user) { + throw new common_1.UnauthorizedException('کاربر یافت نشد'); + } + await this.prisma.otpChallenge.deleteMany({ where: { phone } }); + const accessToken = await this.signCustomerToken(user.id, user.phone); + return { + accessToken, + user: this.mapCustomer(user), + }; + } + async adminLogin(dto) { + const phone = (0, phone_1.normalizePhone)((0, phone_1.toEnglishDigits)(dto.phone)); + const admin = await this.prisma.adminUser.findUnique({ where: { phone } }); + if (!admin || !admin.isActive) { + throw new common_1.UnauthorizedException('نام کاربری یا رمز عبور نادرست است'); + } + const ok = await bcrypt.compare(dto.password, admin.passwordHash); + if (!ok) { + throw new common_1.UnauthorizedException('نام کاربری یا رمز عبور نادرست است'); + } + await this.prisma.adminUser.update({ + where: { id: admin.id }, + data: { lastLoginAt: new Date() }, + }); + const accessToken = await this.jwt.signAsync({ + sub: admin.id, + type: 'admin', + role: admin.role, + phone: admin.phone, + }); + return { + accessToken, + user: { + id: admin.id, + fullName: admin.fullName, + phone: admin.phone, + email: admin.email, + role: admin.role, + }, + }; + } + async me(userId, type) { + if (type === 'admin') { + const admin = await this.prisma.adminUser.findUnique({ where: { id: userId } }); + if (!admin) + throw new common_1.UnauthorizedException(); + return { + id: admin.id, + fullName: admin.fullName, + phone: admin.phone, + email: admin.email, + role: admin.role, + }; + } + const user = await this.prisma.customer.findUnique({ where: { id: userId } }); + if (!user) + throw new common_1.UnauthorizedException(); + return this.mapCustomer(user); + } + async updateProfile(userId, dto) { + const user = await this.prisma.customer.update({ + where: { id: userId }, + data: { + firstName: dto.firstName?.trim(), + lastName: dto.lastName?.trim(), + nationalId: dto.nationalId?.trim() || null, + }, + }); + return this.mapCustomer(user); + } + async signCustomerToken(id, phone) { + return this.jwt.signAsync({ + sub: id, + type: 'customer', + phone, + }); + } + mapCustomer(user) { + return { + id: user.id, + firstName: user.firstName, + lastName: user.lastName, + phone: user.phone, + nationalId: user.nationalId ?? undefined, + createdAt: user.createdAt.toISOString(), + }; + } +}; +exports.AuthService = AuthService; +exports.AuthService = AuthService = __decorate([ + (0, common_1.Injectable)(), + __metadata("design:paramtypes", [prisma_service_1.PrismaService, + jwt_1.JwtService, + config_1.ConfigService]) +], AuthService); +//# sourceMappingURL=auth.service.js.map \ No newline at end of file diff --git a/dist/auth/auth.service.js.map b/dist/auth/auth.service.js.map new file mode 100644 index 0000000..23665b6 --- /dev/null +++ b/dist/auth/auth.service.js.map @@ -0,0 +1 @@ +{"version":3,"file":"auth.service.js","sourceRoot":"","sources":["../../src/auth/auth.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAIwB;AACxB,2CAA+C;AAC/C,qCAAyC;AACzC,iDAAmC;AACnC,6DAAyD;AAOzD,iDAAsF;AAG/E,IAAM,WAAW,GAAjB,MAAM,WAAW;IAEH;IACA;IACA;IAHnB,YACmB,MAAqB,EACrB,GAAe,EACf,MAAqB;QAFrB,WAAM,GAAN,MAAM,CAAe;QACrB,QAAG,GAAH,GAAG,CAAY;QACf,WAAM,GAAN,MAAM,CAAe;IACrC,CAAC;IAEJ,KAAK,CAAC,UAAU,CAAC,GAAkB;QACjC,MAAM,KAAK,GAAG,IAAA,sBAAc,EAAC,IAAA,uBAAe,EAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;QACzD,IAAI,CAAC,IAAA,oBAAY,EAAC,KAAK,CAAC,EAAE,CAAC;YACzB,MAAM,IAAI,4BAAmB,CAAC,0BAA0B,CAAC,CAAC;QAC5D,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;QAC7E,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAE3C,IAAI,UAAU,EAAE,CAAC;YACf,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAE,CAAC;gBACpD,MAAM,IAAI,4BAAmB,CAAC,+BAA+B,CAAC,CAAC;YACjE,CAAC;YAC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AAC,SAAS,EAAE,IAAI,EAAE;gBAChC,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,IAAI,EAAE;gBAC9B,UAAU,EAAE,GAAG,CAAC,UAAU,EAAE,IAAI,EAAE,IAAI,IAAI;aAC3C;SACF,CAAC,CAAC;QACH,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAEO,KAAK,CAAC,iBAAiB,CAAC,EAAU,EAAE,KAAa;QACvD,OAAO,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC;YACxB,GAAG,EAAE,EAAE;YACP,IAAI,EAAE,UAAU;YAChB,KAAK;SACN,CAAC,CAAC;IACL,CAAC;IAEO,WAAW,CAAC,IAOnB;QACC,OAAO;YACL,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,UAAU,EAAE,IAAI,CAAC,UAAU,IAAI,SAAS;YACxC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE;SACxC,CAAC;IACJ,CAAC;CACF,CAAA;AAxLY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;qCAGgB,8BAAa;QAChB,gBAAU;QACP,sBAAa;GAJ7B,WAAW,CAwLvB"} \ No newline at end of file diff --git a/dist/auth/dto/auth.dto.d.ts b/dist/auth/dto/auth.dto.d.ts new file mode 100644 index 0000000..5bb494b --- /dev/null +++ b/dist/auth/dto/auth.dto.d.ts @@ -0,0 +1,19 @@ +export declare class RequestOtpDto { + phone: string; + firstName?: string; + lastName?: string; + isRegister?: boolean; +} +export declare class VerifyOtpDto { + phone: string; + code: string; +} +export declare class AdminLoginDto { + phone: string; + password: string; +} +export declare class UpdateProfileDto { + firstName?: string; + lastName?: string; + nationalId?: string; +} diff --git a/dist/auth/dto/auth.dto.js b/dist/auth/dto/auth.dto.js new file mode 100644 index 0000000..2792379 --- /dev/null +++ b/dist/auth/dto/auth.dto.js @@ -0,0 +1,89 @@ +"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.UpdateProfileDto = exports.AdminLoginDto = exports.VerifyOtpDto = exports.RequestOtpDto = void 0; +const class_validator_1 = require("class-validator"); +class RequestOtpDto { + phone; + firstName; + lastName; + isRegister; +} +exports.RequestOtpDto = RequestOtpDto; +__decorate([ + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], RequestOtpDto.prototype, "phone", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], RequestOtpDto.prototype, "firstName", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], RequestOtpDto.prototype, "lastName", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsBoolean)(), + __metadata("design:type", Boolean) +], RequestOtpDto.prototype, "isRegister", void 0); +class VerifyOtpDto { + phone; + code; +} +exports.VerifyOtpDto = VerifyOtpDto; +__decorate([ + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], VerifyOtpDto.prototype, "phone", void 0); +__decorate([ + (0, class_validator_1.IsString)(), + (0, class_validator_1.MinLength)(4), + __metadata("design:type", String) +], VerifyOtpDto.prototype, "code", void 0); +class AdminLoginDto { + phone; + password; +} +exports.AdminLoginDto = AdminLoginDto; +__decorate([ + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], AdminLoginDto.prototype, "phone", void 0); +__decorate([ + (0, class_validator_1.IsString)(), + (0, class_validator_1.MinLength)(4), + __metadata("design:type", String) +], AdminLoginDto.prototype, "password", void 0); +class UpdateProfileDto { + firstName; + lastName; + nationalId; +} +exports.UpdateProfileDto = UpdateProfileDto; +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], UpdateProfileDto.prototype, "firstName", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], UpdateProfileDto.prototype, "lastName", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], UpdateProfileDto.prototype, "nationalId", void 0); +//# sourceMappingURL=auth.dto.js.map \ No newline at end of file diff --git a/dist/auth/dto/auth.dto.js.map b/dist/auth/dto/auth.dto.js.map new file mode 100644 index 0000000..c5b34da --- /dev/null +++ b/dist/auth/dto/auth.dto.js.map @@ -0,0 +1 @@ +{"version":3,"file":"auth.dto.js","sourceRoot":"","sources":["../../../src/auth/dto/auth.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAA6E;AAE7E,MAAa,aAAa;IAExB,KAAK,CAAU;IAIf,SAAS,CAAU;IAInB,QAAQ,CAAU;IAIlB,UAAU,CAAW;CACtB;AAfD,sCAeC;AAbC;IADC,IAAA,0BAAQ,GAAE;;4CACI;AAIf;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;gDACQ;AAInB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;+CACO;AAIlB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,2BAAS,GAAE;;iDACS;AAGvB,MAAa,YAAY;IAEvB,KAAK,CAAU;IAIf,IAAI,CAAU;CACf;AAPD,oCAOC;AALC;IADC,IAAA,0BAAQ,GAAE;;2CACI;AAIf;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,2BAAS,EAAC,CAAC,CAAC;;0CACC;AAGhB,MAAa,aAAa;IAExB,KAAK,CAAU;IAIf,QAAQ,CAAU;CACnB;AAPD,sCAOC;AALC;IADC,IAAA,0BAAQ,GAAE;;4CACI;AAIf;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,2BAAS,EAAC,CAAC,CAAC;;+CACK;AAGpB,MAAa,gBAAgB;IAG3B,SAAS,CAAU;IAInB,QAAQ,CAAU;IAIlB,UAAU,CAAU;CACrB;AAZD,4CAYC;AATC;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;mDACQ;AAInB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;kDACO;AAIlB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;oDACS"} \ No newline at end of file diff --git a/dist/carts/carts.controller.d.ts b/dist/carts/carts.controller.d.ts new file mode 100644 index 0000000..69854cb --- /dev/null +++ b/dist/carts/carts.controller.d.ts @@ -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; + }>; +} diff --git a/dist/carts/carts.controller.js b/dist/carts/carts.controller.js new file mode 100644 index 0000000..27cb17f --- /dev/null +++ b/dist/carts/carts.controller.js @@ -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 \ No newline at end of file diff --git a/dist/carts/carts.controller.js.map b/dist/carts/carts.controller.js.map new file mode 100644 index 0000000..da9c566 --- /dev/null +++ b/dist/carts/carts.controller.js.map @@ -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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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"} \ No newline at end of file diff --git a/dist/carts/carts.module.d.ts b/dist/carts/carts.module.d.ts new file mode 100644 index 0000000..7cae9b9 --- /dev/null +++ b/dist/carts/carts.module.d.ts @@ -0,0 +1,2 @@ +export declare class CartsModule { +} diff --git a/dist/carts/carts.module.js b/dist/carts/carts.module.js new file mode 100644 index 0000000..6b72e3d --- /dev/null +++ b/dist/carts/carts.module.js @@ -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 \ No newline at end of file diff --git a/dist/carts/carts.module.js.map b/dist/carts/carts.module.js.map new file mode 100644 index 0000000..bcf209a --- /dev/null +++ b/dist/carts/carts.module.js.map @@ -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"} \ No newline at end of file diff --git a/dist/carts/carts.service.d.ts b/dist/carts/carts.service.d.ts new file mode 100644 index 0000000..7fa640e --- /dev/null +++ b/dist/carts/carts.service.d.ts @@ -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; +} diff --git a/dist/carts/carts.service.js b/dist/carts/carts.service.js new file mode 100644 index 0000000..3fa6649 --- /dev/null +++ b/dist/carts/carts.service.js @@ -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 \ No newline at end of file diff --git a/dist/carts/carts.service.js.map b/dist/carts/carts.service.js.map new file mode 100644 index 0000000..6b8af69 --- /dev/null +++ b/dist/carts/carts.service.js.map @@ -0,0 +1 @@ +{"version":3,"file":"carts.service.js","sourceRoot":"","sources":["../../src/carts/carts.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAIwB;AACxB,6DAAyD;AAQlD,IAAM,YAAY,GAAlB,MAAM,YAAY;IACM;IAA7B,YAA6B,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;IAEtD,KAAK,CAAC,OAAO,CAAC,MAAc;QAC1B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QAC3C,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,MAAc,EAAE,GAAmB;QAC/C,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OA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to/cart.dto.d.ts @@ -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; +} diff --git a/dist/carts/dto/cart.dto.js b/dist/carts/dto/cart.dto.js new file mode 100644 index 0000000..d030002 --- /dev/null +++ b/dist/carts/dto/cart.dto.js @@ -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 \ No newline at end of file diff --git a/dist/carts/dto/cart.dto.js.map b/dist/carts/dto/cart.dto.js.map new file mode 100644 index 0000000..e392de6 --- /dev/null +++ b/dist/carts/dto/cart.dto.js.map @@ -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"} \ No newline at end of file diff --git a/dist/cash-payments/cash-payments.controller.d.ts b/dist/cash-payments/cash-payments.controller.d.ts new file mode 100644 index 0000000..a72fd84 --- /dev/null +++ b/dist/cash-payments/cash-payments.controller.d.ts @@ -0,0 +1,68 @@ +import { CashPaymentStatus } from '@prisma/client'; +import { CashPaymentsService } from './cash-payments.service'; +import type { AuthPrincipal } from '../common/decorators/current-user.decorator'; +import { SubmitCashReceiptDto, UpdateCashPaymentStatusDto } from './dto/cash-payment.dto'; +export declare class CashPaymentsController { + private readonly cashPaymentsService; + constructor(cashPaymentsService: CashPaymentsService); + submitReceipt(user: AuthPrincipal, orderId: string, dto: SubmitCashReceiptDto): Promise<{ + id: string; + orderId: string; + orderNumber: string; + customerName: string; + amount: number; + paidAmount: number | null; + transferDate: string | null; + transferTime: string | undefined; + trackingNumber: string; + trackingCode: string; + destinationAccountId: string | undefined; + receiptImage: string | undefined; + notes: string | undefined; + expiresAt: string; + status: import("@prisma/client").$Enums.CashPaymentStatus; + submittedAt: string | undefined; + createdAt: string; + updatedAt: string; + }>; + findAll(status?: CashPaymentStatus): Promise<{ + id: string; + orderId: string; + orderNumber: string; + customerName: string; + amount: number; + paidAmount: number | null; + transferDate: string | null; + transferTime: string | undefined; + trackingNumber: string; + trackingCode: string; + destinationAccountId: string | undefined; + receiptImage: string | undefined; + notes: string | undefined; + expiresAt: string; + status: import("@prisma/client").$Enums.CashPaymentStatus; + submittedAt: string | undefined; + createdAt: string; + updatedAt: string; + }[]>; + updateStatus(user: AuthPrincipal, id: string, dto: UpdateCashPaymentStatusDto): Promise<{ + id: string; + orderId: string; + orderNumber: string; + customerName: string; + amount: number; + paidAmount: number | null; + transferDate: string | null; + transferTime: string | undefined; + trackingNumber: string; + trackingCode: string; + destinationAccountId: string | undefined; + receiptImage: string | undefined; + notes: string | undefined; + expiresAt: string; + status: import("@prisma/client").$Enums.CashPaymentStatus; + submittedAt: string | undefined; + createdAt: string; + updatedAt: string; + }>; +} diff --git a/dist/cash-payments/cash-payments.controller.js b/dist/cash-payments/cash-payments.controller.js new file mode 100644 index 0000000..5c339f2 --- /dev/null +++ b/dist/cash-payments/cash-payments.controller.js @@ -0,0 +1,70 @@ +"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.CashPaymentsController = void 0; +const common_1 = require("@nestjs/common"); +const client_1 = require("@prisma/client"); +const cash_payments_service_1 = require("./cash-payments.service"); +const auth_decorators_1 = require("../common/decorators/auth.decorators"); +const current_user_decorator_1 = require("../common/decorators/current-user.decorator"); +const cash_payment_dto_1 = require("./dto/cash-payment.dto"); +let CashPaymentsController = class CashPaymentsController { + cashPaymentsService; + constructor(cashPaymentsService) { + this.cashPaymentsService = cashPaymentsService; + } + submitReceipt(user, orderId, dto) { + return this.cashPaymentsService.submitReceipt(user.id, orderId, dto); + } + findAll(status) { + return this.cashPaymentsService.findAll(status); + } + updateStatus(user, id, dto) { + return this.cashPaymentsService.updateStatus(id, user.id, dto); + } +}; +exports.CashPaymentsController = CashPaymentsController; +__decorate([ + (0, auth_decorators_1.AuthType)('customer'), + (0, common_1.Post)('orders/:orderId/cash-receipt'), + __param(0, (0, current_user_decorator_1.CurrentUser)()), + __param(1, (0, common_1.Param)('orderId')), + __param(2, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [Object, String, cash_payment_dto_1.SubmitCashReceiptDto]), + __metadata("design:returntype", void 0) +], CashPaymentsController.prototype, "submitReceipt", null); +__decorate([ + (0, auth_decorators_1.AuthType)('admin'), + (0, common_1.Get)('admin/cash-payments'), + __param(0, (0, common_1.Query)('status')), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String]), + __metadata("design:returntype", void 0) +], CashPaymentsController.prototype, "findAll", null); +__decorate([ + (0, auth_decorators_1.AuthType)('admin'), + (0, common_1.Patch)('admin/cash-payments/:id/status'), + __param(0, (0, current_user_decorator_1.CurrentUser)()), + __param(1, (0, common_1.Param)('id')), + __param(2, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [Object, String, cash_payment_dto_1.UpdateCashPaymentStatusDto]), + __metadata("design:returntype", void 0) +], CashPaymentsController.prototype, "updateStatus", null); +exports.CashPaymentsController = CashPaymentsController = __decorate([ + (0, common_1.Controller)(), + __metadata("design:paramtypes", [cash_payments_service_1.CashPaymentsService]) +], CashPaymentsController); +//# sourceMappingURL=cash-payments.controller.js.map \ No newline at end of file diff --git a/dist/cash-payments/cash-payments.controller.js.map b/dist/cash-payments/cash-payments.controller.js.map new file mode 100644 index 0000000..aef2e72 --- /dev/null +++ b/dist/cash-payments/cash-payments.controller.js.map @@ -0,0 +1 @@ +{"version":3,"file":"cash-payments.controller.js","sourceRoot":"","sources":["../../src/cash-payments/cash-payments.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAQwB;AACxB,2CAAmD;AACnD,mEAA8D;AAC9D,0EAAgE;AAChE,wFAA0E;AAE1E,6DAGgC;AAGzB,IAAM,sBAAsB,GAA5B,MAAM,sBA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C"} \ No newline at end of file diff --git a/dist/cash-payments/cash-payments.module.d.ts b/dist/cash-payments/cash-payments.module.d.ts new file mode 100644 index 0000000..1d8af9e --- /dev/null +++ b/dist/cash-payments/cash-payments.module.d.ts @@ -0,0 +1,2 @@ +export declare class CashPaymentsModule { +} diff --git a/dist/cash-payments/cash-payments.module.js b/dist/cash-payments/cash-payments.module.js new file mode 100644 index 0000000..ccde3cd --- /dev/null +++ b/dist/cash-payments/cash-payments.module.js @@ -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.CashPaymentsModule = void 0; +const common_1 = require("@nestjs/common"); +const cash_payments_controller_1 = require("./cash-payments.controller"); +const cash_payments_service_1 = require("./cash-payments.service"); +let CashPaymentsModule = class CashPaymentsModule { +}; +exports.CashPaymentsModule = CashPaymentsModule; +exports.CashPaymentsModule = CashPaymentsModule = __decorate([ + (0, common_1.Module)({ + controllers: [cash_payments_controller_1.CashPaymentsController], + providers: [cash_payments_service_1.CashPaymentsService], + exports: [cash_payments_service_1.CashPaymentsService], + }) +], CashPaymentsModule); +//# sourceMappingURL=cash-payments.module.js.map \ No newline at end of file diff --git a/dist/cash-payments/cash-payments.module.js.map b/dist/cash-payments/cash-payments.module.js.map new file mode 100644 index 0000000..b43604d --- /dev/null +++ b/dist/cash-payments/cash-payments.module.js.map @@ -0,0 +1 @@ +{"version":3,"file":"cash-payments.module.js","sourceRoot":"","sources":["../../src/cash-payments/cash-payments.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,yEAAoE;AACpE,mEAA8D;AAOvD,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;CAAG,CAAA;AAArB,gDAAkB;6BAAlB,kBAAkB;IAL9B,IAAA,eAAM,EAAC;QACN,WAAW,EAAE,CAAC,iDAAsB,CAAC;QACrC,SAAS,EAAE,CAAC,2CAAmB,CAAC;QAChC,OAAO,EAAE,CAAC,2CAAmB,CAAC;KAC/B,CAAC;GACW,kBAAkB,CAAG"} \ No newline at end of file diff --git a/dist/cash-payments/cash-payments.service.d.ts b/dist/cash-payments/cash-payments.service.d.ts new file mode 100644 index 0000000..207fe7c --- /dev/null +++ b/dist/cash-payments/cash-payments.service.d.ts @@ -0,0 +1,68 @@ +import { CashPaymentStatus } from '@prisma/client'; +import { PrismaService } from '../prisma/prisma.service'; +import { SubmitCashReceiptDto, UpdateCashPaymentStatusDto } from './dto/cash-payment.dto'; +export declare class CashPaymentsService { + private readonly prisma; + constructor(prisma: PrismaService); + submitReceipt(userId: string, orderId: string, dto: SubmitCashReceiptDto): Promise<{ + id: string; + orderId: string; + orderNumber: string; + customerName: string; + amount: number; + paidAmount: number | null; + transferDate: string | null; + transferTime: string | undefined; + trackingNumber: string; + trackingCode: string; + destinationAccountId: string | undefined; + receiptImage: string | undefined; + notes: string | undefined; + expiresAt: string; + status: import("@prisma/client").$Enums.CashPaymentStatus; + submittedAt: string | undefined; + createdAt: string; + updatedAt: string; + }>; + findAll(status?: CashPaymentStatus): Promise<{ + id: string; + orderId: string; + orderNumber: string; + customerName: string; + amount: number; + paidAmount: number | null; + transferDate: string | null; + transferTime: string | undefined; + trackingNumber: string; + trackingCode: string; + destinationAccountId: string | undefined; + receiptImage: string | undefined; + notes: string | undefined; + expiresAt: string; + status: import("@prisma/client").$Enums.CashPaymentStatus; + submittedAt: string | undefined; + createdAt: string; + updatedAt: string; + }[]>; + updateStatus(id: string, adminId: string, dto: UpdateCashPaymentStatusDto): Promise<{ + id: string; + orderId: string; + orderNumber: string; + customerName: string; + amount: number; + paidAmount: number | null; + transferDate: string | null; + transferTime: string | undefined; + trackingNumber: string; + trackingCode: string; + destinationAccountId: string | undefined; + receiptImage: string | undefined; + notes: string | undefined; + expiresAt: string; + status: import("@prisma/client").$Enums.CashPaymentStatus; + submittedAt: string | undefined; + createdAt: string; + updatedAt: string; + }>; + private mapReceipt; +} diff --git a/dist/cash-payments/cash-payments.service.js b/dist/cash-payments/cash-payments.service.js new file mode 100644 index 0000000..81bfebf --- /dev/null +++ b/dist/cash-payments/cash-payments.service.js @@ -0,0 +1,175 @@ +"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.CashPaymentsService = void 0; +const common_1 = require("@nestjs/common"); +const client_1 = require("@prisma/client"); +const prisma_service_1 = require("../prisma/prisma.service"); +const name_1 = require("../common/utils/name"); +let CashPaymentsService = class CashPaymentsService { + prisma; + constructor(prisma) { + this.prisma = prisma; + } + async submitReceipt(userId, orderId, dto) { + const order = await this.prisma.order.findUnique({ + where: { id: orderId }, + include: { cashReceipt: true }, + }); + if (!order) + throw new common_1.NotFoundException('سفارش یافت نشد'); + if (order.userId !== userId) { + throw new common_1.ForbiddenException('دسترسی به این سفارش مجاز نیست'); + } + if (order.settlementType !== client_1.SettlementType.cash) { + throw new common_1.BadRequestException('این سفارش تسویه نقدی نیست'); + } + if (order.cashInvoiceExpiresAt && + order.cashInvoiceExpiresAt.getTime() < Date.now()) { + throw new common_1.BadRequestException('مهلت پرداخت فاکتور نقدی به پایان رسیده است'); + } + const account = await this.prisma.bankAccount.findFirst({ + where: { + id: dto.destinationAccountId, + companyId: order.companyId, + isActive: true, + }, + }); + if (!account) { + throw new common_1.BadRequestException('حساب مقصد نامعتبر است'); + } + const receipt = await this.prisma.$transaction(async (tx) => { + const data = { + amount: dto.amount, + paidAmount: dto.paidAmount ?? dto.amount, + transferDate: new Date(dto.transferDate), + transferTime: dto.transferTime.trim(), + trackingNumber: dto.trackingNumber.trim(), + destinationAccountId: dto.destinationAccountId, + receiptImage: dto.receiptImage || null, + notes: dto.notes?.trim() || null, + expiresAt: order.cashInvoiceExpiresAt, + status: client_1.CashPaymentStatus.pending_review, + submittedAt: new Date(), + }; + const saved = order.cashReceipt + ? await tx.cashPaymentReceipt.update({ + where: { orderId }, + data, + }) + : await tx.cashPaymentReceipt.create({ + data: { orderId, ...data }, + }); + await tx.order.update({ + where: { id: orderId }, + data: { status: client_1.OrderStatus.awaiting_cash_confirmation }, + }); + await tx.orderStatusHistory.create({ + data: { + orderId, + fromStatus: order.status, + toStatus: client_1.OrderStatus.awaiting_cash_confirmation, + changedBy: 'customer', + note: 'رسید پرداخت نقدی ارسال شد', + }, + }); + return saved; + }); + return this.mapReceipt(receipt, order.orderNumber, ''); + } + async findAll(status) { + const receipts = await this.prisma.cashPaymentReceipt.findMany({ + where: status ? { status } : undefined, + orderBy: { createdAt: 'desc' }, + include: { + order: { + include: { user: true }, + }, + }, + }); + return receipts.map((r) => this.mapReceipt(r, r.order.orderNumber, (0, name_1.joinFullName)(r.order.user.firstName, r.order.user.lastName))); + } + async updateStatus(id, adminId, dto) { + const receipt = await this.prisma.cashPaymentReceipt.findUnique({ + where: { id }, + include: { order: { include: { user: true } } }, + }); + if (!receipt) + throw new common_1.NotFoundException('رسید نقدی یافت نشد'); + const updated = await this.prisma.$transaction(async (tx) => { + const result = await tx.cashPaymentReceipt.update({ + where: { id }, + data: { + status: dto.status, + notes: dto.note + ? [receipt.notes, dto.note].filter(Boolean).join('\n') + : receipt.notes, + }, + include: { order: { include: { user: true } } }, + }); + let nextStatus = null; + if (dto.status === client_1.CashPaymentStatus.approved) { + nextStatus = client_1.OrderStatus.cash_confirmed; + } + else if (dto.status === client_1.CashPaymentStatus.rejected) { + nextStatus = client_1.OrderStatus.needs_correction; + } + else if (dto.status === client_1.CashPaymentStatus.expired) { + nextStatus = client_1.OrderStatus.expired; + } + if (nextStatus && nextStatus !== receipt.order.status) { + await tx.order.update({ + where: { id: receipt.orderId }, + data: { status: nextStatus }, + }); + await tx.orderStatusHistory.create({ + data: { + orderId: receipt.orderId, + fromStatus: receipt.order.status, + toStatus: nextStatus, + changedBy: `admin:${adminId}`, + note: dto.note || `وضعیت پرداخت نقدی: ${dto.status}`, + }, + }); + } + return result; + }); + return this.mapReceipt(updated, updated.order.orderNumber, (0, name_1.joinFullName)(updated.order.user.firstName, updated.order.user.lastName)); + } + mapReceipt(r, orderNumber, customerName) { + return { + id: r.id, + orderId: r.orderId, + orderNumber, + customerName, + amount: r.amount, + paidAmount: r.paidAmount, + transferDate: r.transferDate?.toISOString() ?? null, + transferTime: r.transferTime ?? undefined, + trackingNumber: r.trackingNumber ?? '', + trackingCode: r.trackingNumber ?? '', + destinationAccountId: r.destinationAccountId ?? undefined, + receiptImage: r.receiptImage ?? undefined, + notes: r.notes ?? undefined, + expiresAt: r.expiresAt?.toISOString() ?? '', + status: r.status, + submittedAt: r.submittedAt?.toISOString(), + createdAt: r.createdAt.toISOString(), + updatedAt: r.updatedAt.toISOString(), + }; + } +}; +exports.CashPaymentsService = CashPaymentsService; +exports.CashPaymentsService = CashPaymentsService = __decorate([ + (0, common_1.Injectable)(), + __metadata("design:paramtypes", [prisma_service_1.PrismaService]) +], CashPaymentsService); +//# sourceMappingURL=cash-payments.service.js.map \ No newline at end of file diff --git a/dist/cash-payments/cash-payments.service.js.map b/dist/cash-payments/cash-payments.service.js.map new file mode 100644 index 0000000..ece4080 --- /dev/null +++ b/dist/cash-payments/cash-payments.service.js.map @@ -0,0 +1 @@ +{"version":3,"file":"cash-payments.service.js","sourceRoot":"","sources":["../../src/cash-payments/cash-payments.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAKwB;AACxB,2CAIwB;AACxB,6DAAyD;AAKzD,+CAAoD;AAG7C,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IACD;IAA7B,YAA6B,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;IAEtD,KAAK,CAAC,aAAa,CACjB,MAAc,EACd,OAAe,EACf,GAAyB;QAEzB,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC;YAC/C,KAAK,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE;YACtB,OAAO,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE;SAC/B,CAAC,CAAC;QACH,IAAI,CAAC,KAAK;YAAE,MAAM,IAAI,0BAAiB,CAAC,gBAAgB,CAAC,CAAC;QAC1D,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;YAC5B,MAAM,IAAI,2BAAkB,CAAC,+BAA+B,CAAC,CAAC;QAChE,CAAC;QACD,IAAI,KAAK,CAAC,cAAc,KAAK,uBAAc,CAAC,IAAI,EAAE,CAAC;YACjD,MAAM,IAAI,4BAAmB,CAAC,2BAA2B,CAAC,CAAC;QAC7D,CAAC;QACD,IACE,KAAK,CAAC,oBAAoB;YAC1B,KAAK,CAAC,oBAAoB,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,EACjD,CAAC;YACD,MAAM,IAAI,4BAAmB,CAAC,4CAA4C,CAAC,CAAC;QAC9E,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC;YACtD,KAAK,EAAE;gBACL,EAAE,EAAE,GA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AAE,IAAI,IAAI;YACnD,YAAY,EAAE,CAAC,CAAC,YAAY,IAAI,SAAS;YACzC,cAAc,EAAE,CAAC,CAAC,cAAc,IAAI,EAAE;YACtC,YAAY,EAAE,CAAC,CAAC,cAAc,IAAI,EAAE;YACpC,oBAAoB,EAAE,CAAC,CAAC,oBAAoB,IAAI,SAAS;YACzD,YAAY,EAAE,CAAC,CAAC,YAAY,IAAI,SAAS;YACzC,KAAK,EAAE,CAAC,CAAC,KAAK,IAAI,SAAS;YAC3B,SAAS,EAAE,CAAC,CAAC,SAAS,EAAE,WAAW,EAAE,IAAI,EAAE;YAC3C,MAAM,EAAE,CAAC,CAAC,MAAM;YAChB,WAAW,EAAE,CAAC,CAAC,WAAW,EAAE,WAAW,EAAE;YACzC,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,WAAW,EAAE;YACpC,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,WAAW,EAAE;SACrC,CAAC;IACJ,CAAC;CACF,CAAA;AAxMY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,mBAAU,GAAE;qCAE0B,8BAAa;GADvC,mBAAmB,CAwM/B"} \ No newline at end of file diff --git a/dist/cash-payments/dto/cash-payment.dto.d.ts b/dist/cash-payments/dto/cash-payment.dto.d.ts new file mode 100644 index 0000000..983dc34 --- /dev/null +++ b/dist/cash-payments/dto/cash-payment.dto.d.ts @@ -0,0 +1,15 @@ +import { CashPaymentStatus } from '@prisma/client'; +export declare class SubmitCashReceiptDto { + amount: number; + paidAmount?: number; + transferDate: string; + transferTime: string; + trackingNumber: string; + destinationAccountId: string; + receiptImage?: string; + notes?: string; +} +export declare class UpdateCashPaymentStatusDto { + status: CashPaymentStatus; + note?: string; +} diff --git a/dist/cash-payments/dto/cash-payment.dto.js b/dist/cash-payments/dto/cash-payment.dto.js new file mode 100644 index 0000000..7a7ca70 --- /dev/null +++ b/dist/cash-payments/dto/cash-payment.dto.js @@ -0,0 +1,82 @@ +"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.UpdateCashPaymentStatusDto = exports.SubmitCashReceiptDto = void 0; +const class_validator_1 = require("class-validator"); +const class_transformer_1 = require("class-transformer"); +const client_1 = require("@prisma/client"); +class SubmitCashReceiptDto { + amount; + paidAmount; + transferDate; + transferTime; + trackingNumber; + destinationAccountId; + receiptImage; + notes; +} +exports.SubmitCashReceiptDto = SubmitCashReceiptDto; +__decorate([ + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsNumber)(), + (0, class_validator_1.Min)(1), + __metadata("design:type", Number) +], SubmitCashReceiptDto.prototype, "amount", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsNumber)(), + (0, class_validator_1.Min)(0), + __metadata("design:type", Number) +], SubmitCashReceiptDto.prototype, "paidAmount", void 0); +__decorate([ + (0, class_validator_1.IsDateString)(), + __metadata("design:type", String) +], SubmitCashReceiptDto.prototype, "transferDate", void 0); +__decorate([ + (0, class_validator_1.IsString)(), + (0, class_validator_1.MinLength)(1), + __metadata("design:type", String) +], SubmitCashReceiptDto.prototype, "transferTime", void 0); +__decorate([ + (0, class_validator_1.IsString)(), + (0, class_validator_1.MinLength)(1), + __metadata("design:type", String) +], SubmitCashReceiptDto.prototype, "trackingNumber", void 0); +__decorate([ + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], SubmitCashReceiptDto.prototype, "destinationAccountId", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], SubmitCashReceiptDto.prototype, "receiptImage", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], SubmitCashReceiptDto.prototype, "notes", void 0); +class UpdateCashPaymentStatusDto { + status; + note; +} +exports.UpdateCashPaymentStatusDto = UpdateCashPaymentStatusDto; +__decorate([ + (0, class_validator_1.IsEnum)(client_1.CashPaymentStatus), + __metadata("design:type", String) +], UpdateCashPaymentStatusDto.prototype, "status", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], UpdateCashPaymentStatusDto.prototype, "note", void 0); +//# sourceMappingURL=cash-payment.dto.js.map \ No newline at end of file diff --git a/dist/cash-payments/dto/cash-payment.dto.js.map b/dist/cash-payments/dto/cash-payment.dto.js.map new file mode 100644 index 0000000..dcd34da --- /dev/null +++ b/dist/cash-payments/dto/cash-payment.dto.js.map @@ -0,0 +1 @@ +{"version":3,"file":"cash-payment.dto.js","sourceRoot":"","sources":["../../../src/cash-payments/dto/cash-payment.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAQyB;AACzB,yDAAyC;AACzC,2CAAmD;AAEnD,MAAa,oBAAoB;IAI/B,MAAM,CAAU;IAMhB,UAAU,CAAU;IAGpB,YAAY,CAAU;IAItB,YAAY,CAAU;IAItB,cAAc,CAAU;IAGxB,oBAAoB,CAAU;IAI9B,YAAY,CAAU;IAItB,KAAK,CAAU;CAChB;AAjCD,oDAiCC;AA7BC;IAHC,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC;IAClB,IAAA,0BAAQ,GAAE;IACV,IAAA,qBAAG,EAAC,CAAC,CAAC;;oDACS;AAMhB;IAJC,IAAA,4BAAU,GAAE;IACZ,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC;IAClB,IAAA,0BAAQ,GAAE;IACV,IAAA,qBAAG,EAAC,CAAC,CAAC;;wDACa;AAGpB;IADC,IAAA,8BAAY,GAAE;;0DACO;AAItB;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,2BAAS,EAAC,CAAC,CAAC;;0DACS;AAItB;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,2BAAS,EAAC,CAAC,CAAC;;4DACW;AAGxB;IADC,IAAA,0BAAQ,GAAE;;kEACmB;AAI9B;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;0DACW;AAItB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;mDACI;AAGjB,MAAa,0BAA0B;IAErC,MAAM,CAAqB;IAI3B,IAAI,CAAU;CACf;AAPD,gEAOC;AALC;IADC,IAAA,wBAAM,EAAC,0BAAiB,CAAC;;0DACC;AAI3B;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;wDACG"} \ No newline at end of file diff --git a/dist/catalogs/catalogs.controller.d.ts b/dist/catalogs/catalogs.controller.d.ts new file mode 100644 index 0000000..a463545 --- /dev/null +++ b/dist/catalogs/catalogs.controller.d.ts @@ -0,0 +1,71 @@ +import { CatalogsService } from './catalogs.service'; +import { CreateCatalogDto, SetCatalogActiveDto, UpdateCatalogDto } from './dto/catalog.dto'; +export declare class CatalogsController { + private readonly catalogsService; + constructor(catalogsService: CatalogsService); + findAll(companyId?: string, activeOnly?: string): Promise<{ + id: string; + companyId: string; + companyName: string; + name: string; + code: string; + description: string | undefined; + displayOrder: number; + isActive: boolean; + productCount: number; + createdAt: string; + updatedAt: string; + }[]>; + findOne(id: string): Promise<{ + id: string; + companyId: string; + companyName: string; + name: string; + code: string; + description: string | undefined; + displayOrder: number; + isActive: boolean; + productCount: number; + createdAt: string; + updatedAt: string; + }>; + create(dto: CreateCatalogDto): Promise<{ + id: string; + companyId: string; + companyName: string; + name: string; + code: string; + description: string | undefined; + displayOrder: number; + isActive: boolean; + productCount: number; + createdAt: string; + updatedAt: string; + }>; + update(id: string, dto: UpdateCatalogDto): Promise<{ + id: string; + companyId: string; + companyName: string; + name: string; + code: string; + description: string | undefined; + displayOrder: number; + isActive: boolean; + productCount: number; + createdAt: string; + updatedAt: string; + }>; + setActive(id: string, dto: SetCatalogActiveDto): Promise<{ + id: string; + companyId: string; + companyName: string; + name: string; + code: string; + description: string | undefined; + displayOrder: number; + isActive: boolean; + productCount: number; + createdAt: string; + updatedAt: string; + }>; +} diff --git a/dist/catalogs/catalogs.controller.js b/dist/catalogs/catalogs.controller.js new file mode 100644 index 0000000..9fd6e8b --- /dev/null +++ b/dist/catalogs/catalogs.controller.js @@ -0,0 +1,89 @@ +"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.CatalogsController = void 0; +const common_1 = require("@nestjs/common"); +const catalogs_service_1 = require("./catalogs.service"); +const auth_decorators_1 = require("../common/decorators/auth.decorators"); +const catalog_dto_1 = require("./dto/catalog.dto"); +let CatalogsController = class CatalogsController { + catalogsService; + constructor(catalogsService) { + this.catalogsService = catalogsService; + } + findAll(companyId, activeOnly) { + return this.catalogsService.findAll(companyId, activeOnly === 'true' || activeOnly === '1'); + } + findOne(id) { + return this.catalogsService.findOne(id); + } + create(dto) { + return this.catalogsService.create(dto); + } + update(id, dto) { + return this.catalogsService.update(id, dto); + } + setActive(id, dto) { + return this.catalogsService.setActive(id, dto.isActive); + } +}; +exports.CatalogsController = CatalogsController; +__decorate([ + (0, auth_decorators_1.AuthType)('any'), + (0, common_1.Get)(), + __param(0, (0, common_1.Query)('companyId')), + __param(1, (0, common_1.Query)('activeOnly')), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String, String]), + __metadata("design:returntype", void 0) +], CatalogsController.prototype, "findAll", null); +__decorate([ + (0, auth_decorators_1.AuthType)('any'), + (0, common_1.Get)(':id'), + __param(0, (0, common_1.Param)('id')), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String]), + __metadata("design:returntype", void 0) +], CatalogsController.prototype, "findOne", null); +__decorate([ + (0, auth_decorators_1.AuthType)('admin'), + (0, common_1.Post)(), + __param(0, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [catalog_dto_1.CreateCatalogDto]), + __metadata("design:returntype", void 0) +], CatalogsController.prototype, "create", null); +__decorate([ + (0, auth_decorators_1.AuthType)('admin'), + (0, common_1.Patch)(':id'), + __param(0, (0, common_1.Param)('id')), + __param(1, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String, catalog_dto_1.UpdateCatalogDto]), + __metadata("design:returntype", void 0) +], CatalogsController.prototype, "update", null); +__decorate([ + (0, auth_decorators_1.AuthType)('admin'), + (0, common_1.Patch)(':id/active'), + __param(0, (0, common_1.Param)('id')), + __param(1, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String, catalog_dto_1.SetCatalogActiveDto]), + __metadata("design:returntype", void 0) +], CatalogsController.prototype, "setActive", null); +exports.CatalogsController = CatalogsController = __decorate([ + (0, common_1.Controller)('catalogs'), + __metadata("design:paramtypes", [catalogs_service_1.CatalogsService]) +], CatalogsController); +//# sourceMappingURL=catalogs.controller.js.map \ No newline at end of file diff --git a/dist/catalogs/catalogs.controller.js.map b/dist/catalogs/catalogs.controller.js.map new file mode 100644 index 0000000..96d0eca --- /dev/null +++ b/dist/catalogs/catalogs.controller.js.map @@ -0,0 +1 @@ +{"version":3,"file":"catalogs.controller.js","sourceRoot":"","sources":["../../src/catalogs/catalogs.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAQwB;AACxB,yDAAqD;AACrD,0EAAgE;AAChE,mDAI2B;AAGpB,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IACA;IAA7B,YAA6B,eAAgC;QAAhC,oBAAe,GAAf,eAAe,CAAiB;IAAG,CAAC;IAIjE,OAAO,CACe,SAAkB,EACjB,UAAmB;QAExC,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CACjC,SAAS,EACT,UAAU,KAAK,MAAM,IAAI,UAAU,KAAK,GAAG,CAC5C,CAAC;IACJ,CAAC;IAID,OAAO,CAAc,EAAU;QAC7B,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC1C,CAAC;IAID,MAAM,CAAS,GAAqB;QAClC,OAAO,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC1C,CAAC;IAID,MAAM,CAAc,EAAU,EAAU,GAAqB;QAC3D,OAAO,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IAC9C,CAAC;IAID,SAAS,CAAc,EAAU,EAAU,GAAwB;QACjE,OAAO,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC1D,CAAC;CACF,CAAA;AAtCY,gDAAkB;AAK7B;IAFC,IAAA,0BAAQ,EAAC,KAAK,CAAC;IACf,IAAA,YAAG,GAAE;IAEH,WAAA,IAAA,cAAK,EAAC,WAAW,CAAC,CAAA;IAClB,WAAA,IAAA,cAAK,EAAC,YAAY,CAAC,CAAA;;;;iDAMrB;AAID;IAFC,IAAA,0BAAQ,EAAC,KAAK,CAAC;IACf,IAAA,YAAG,EAAC,KAAK,CAAC;IACF,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;;;;iDAEnB;AAID;IAFC,IAAA,0BAAQ,EAAC,OAAO,CAAC;IACjB,IAAA,aAAI,GAAE;IACC,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAM,8BAAgB;;gDAEnC;AAID;IAFC,IAAA,0BAAQ,EAAC,OAAO,CAAC;IACjB,IAAA,cAAK,EAAC,KAAK,CAAC;IACL,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;IAAc,WAAA,IAAA,aAAI,GAAE,CAAA;;6CAAM,8BAAgB;;gDAE5D;AAID;IAFC,IAAA,0BAAQ,EAAC,OAAO,CAAC;IACjB,IAAA,cAAK,EAAC,YAAY,CAAC;IACT,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;IAAc,WAAA,IAAA,aAAI,GAAE,CAAA;;6CAAM,iCAAmB;;mDAElE;6BArCU,kBAAkB;IAD9B,IAAA,mBAAU,EAAC,UAAU,CAAC;qCAEyB,kCAAe;GADlD,kBAAkB,CAsC9B"} \ No newline at end of file diff --git a/dist/catalogs/catalogs.module.d.ts b/dist/catalogs/catalogs.module.d.ts new file mode 100644 index 0000000..ff570ed --- /dev/null +++ b/dist/catalogs/catalogs.module.d.ts @@ -0,0 +1,2 @@ +export declare class CatalogsModule { +} diff --git a/dist/catalogs/catalogs.module.js b/dist/catalogs/catalogs.module.js new file mode 100644 index 0000000..c63ad89 --- /dev/null +++ b/dist/catalogs/catalogs.module.js @@ -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.CatalogsModule = void 0; +const common_1 = require("@nestjs/common"); +const catalogs_controller_1 = require("./catalogs.controller"); +const catalogs_service_1 = require("./catalogs.service"); +let CatalogsModule = class CatalogsModule { +}; +exports.CatalogsModule = CatalogsModule; +exports.CatalogsModule = CatalogsModule = __decorate([ + (0, common_1.Module)({ + controllers: [catalogs_controller_1.CatalogsController], + providers: [catalogs_service_1.CatalogsService], + exports: [catalogs_service_1.CatalogsService], + }) +], CatalogsModule); +//# sourceMappingURL=catalogs.module.js.map \ No newline at end of file diff --git a/dist/catalogs/catalogs.module.js.map b/dist/catalogs/catalogs.module.js.map new file mode 100644 index 0000000..388bb9a --- /dev/null +++ b/dist/catalogs/catalogs.module.js.map @@ -0,0 +1 @@ +{"version":3,"file":"catalogs.module.js","sourceRoot":"","sources":["../../src/catalogs/catalogs.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,+DAA2D;AAC3D,yDAAqD;AAO9C,IAAM,cAAc,GAApB,MAAM,cAAc;CAAG,CAAA;AAAjB,wCAAc;yBAAd,cAAc;IAL1B,IAAA,eAAM,EAAC;QACN,WAAW,EAAE,CAAC,wCAAkB,CAAC;QACjC,SAAS,EAAE,CAAC,kCAAe,CAAC;QAC5B,OAAO,EAAE,CAAC,kCAAe,CAAC;KAC3B,CAAC;GACW,cAAc,CAAG"} \ No newline at end of file diff --git a/dist/catalogs/catalogs.service.d.ts b/dist/catalogs/catalogs.service.d.ts new file mode 100644 index 0000000..05b2b3a --- /dev/null +++ b/dist/catalogs/catalogs.service.d.ts @@ -0,0 +1,73 @@ +import { PrismaService } from '../prisma/prisma.service'; +import { CreateCatalogDto, UpdateCatalogDto } from './dto/catalog.dto'; +export declare class CatalogsService { + private readonly prisma; + constructor(prisma: PrismaService); + findAll(companyId?: string, activeOnly?: boolean): Promise<{ + id: string; + companyId: string; + companyName: string; + name: string; + code: string; + description: string | undefined; + displayOrder: number; + isActive: boolean; + productCount: number; + createdAt: string; + updatedAt: string; + }[]>; + findOne(id: string): Promise<{ + id: string; + companyId: string; + companyName: string; + name: string; + code: string; + description: string | undefined; + displayOrder: number; + isActive: boolean; + productCount: number; + createdAt: string; + updatedAt: string; + }>; + create(dto: CreateCatalogDto): Promise<{ + id: string; + companyId: string; + companyName: string; + name: string; + code: string; + description: string | undefined; + displayOrder: number; + isActive: boolean; + productCount: number; + createdAt: string; + updatedAt: string; + }>; + update(id: string, dto: UpdateCatalogDto): Promise<{ + id: string; + companyId: string; + companyName: string; + name: string; + code: string; + description: string | undefined; + displayOrder: number; + isActive: boolean; + productCount: number; + createdAt: string; + updatedAt: string; + }>; + setActive(id: string, isActive: boolean): Promise<{ + id: string; + companyId: string; + companyName: string; + name: string; + code: string; + description: string | undefined; + displayOrder: number; + isActive: boolean; + productCount: number; + createdAt: string; + updatedAt: string; + }>; + private ensure; + private map; +} diff --git a/dist/catalogs/catalogs.service.js b/dist/catalogs/catalogs.service.js new file mode 100644 index 0000000..bffb672 --- /dev/null +++ b/dist/catalogs/catalogs.service.js @@ -0,0 +1,144 @@ +"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.CatalogsService = void 0; +const common_1 = require("@nestjs/common"); +const client_1 = require("@prisma/client"); +const prisma_service_1 = require("../prisma/prisma.service"); +let CatalogsService = class CatalogsService { + prisma; + constructor(prisma) { + this.prisma = prisma; + } + async findAll(companyId, activeOnly = false) { + const catalogs = await this.prisma.catalog.findMany({ + where: { + ...(companyId ? { companyId } : {}), + ...(activeOnly ? { isActive: true } : {}), + }, + orderBy: [{ displayOrder: 'asc' }, { name: 'asc' }], + include: { + company: { select: { name: true } }, + _count: { select: { products: true } }, + }, + }); + return catalogs.map((c) => this.map(c)); + } + async findOne(id) { + const catalog = await this.prisma.catalog.findUnique({ + where: { id }, + include: { + company: { select: { name: true } }, + _count: { select: { products: true } }, + }, + }); + if (!catalog) + throw new common_1.NotFoundException('کاتالوگ یافت نشد'); + return this.map(catalog); + } + async create(dto) { + const company = await this.prisma.company.findUnique({ + where: { id: dto.companyId }, + }); + if (!company) + throw new common_1.NotFoundException('شرکت یافت نشد'); + try { + const catalog = await this.prisma.catalog.create({ + data: { + companyId: dto.companyId, + name: dto.name.trim(), + code: dto.code.trim(), + description: dto.description?.trim() || null, + displayOrder: dto.displayOrder ?? 0, + isActive: dto.isActive ?? true, + }, + include: { + company: { select: { name: true } }, + _count: { select: { products: true } }, + }, + }); + return this.map(catalog); + } + catch (e) { + if (e instanceof client_1.Prisma.PrismaClientKnownRequestError && e.code === 'P2002') { + throw new common_1.ConflictException('کد کاتالوگ در این شرکت تکراری است'); + } + throw e; + } + } + async update(id, dto) { + await this.ensure(id); + try { + const catalog = await this.prisma.catalog.update({ + where: { id }, + data: { + name: dto.name?.trim(), + code: dto.code?.trim(), + description: dto.description === undefined + ? undefined + : dto.description?.trim() || null, + displayOrder: dto.displayOrder, + isActive: dto.isActive, + }, + include: { + company: { select: { name: true } }, + _count: { select: { products: true } }, + }, + }); + return this.map(catalog); + } + catch (e) { + if (e instanceof client_1.Prisma.PrismaClientKnownRequestError && e.code === 'P2002') { + throw new common_1.ConflictException('کد کاتالوگ در این شرکت تکراری است'); + } + throw e; + } + } + async setActive(id, isActive) { + await this.ensure(id); + const catalog = await this.prisma.catalog.update({ + where: { id }, + data: { isActive }, + include: { + company: { select: { name: true } }, + _count: { select: { products: true } }, + }, + }); + return this.map(catalog); + } + async ensure(id) { + const catalog = await this.prisma.catalog.findUnique({ where: { id } }); + if (!catalog) + throw new common_1.NotFoundException('کاتالوگ یافت نشد'); + return catalog; + } + map(catalog) { + return { + id: catalog.id, + companyId: catalog.companyId, + companyName: catalog.company.name, + name: catalog.name, + code: catalog.code, + description: catalog.description ?? undefined, + displayOrder: catalog.displayOrder, + isActive: catalog.isActive, + productCount: catalog._count.products, + createdAt: catalog.createdAt.toISOString(), + updatedAt: catalog.updatedAt.toISOString(), + }; + } +}; +exports.CatalogsService = CatalogsService; +exports.CatalogsService = CatalogsService = __decorate([ + (0, common_1.Injectable)(), + __metadata("design:paramtypes", [prisma_service_1.PrismaService]) +], CatalogsService); +//# sourceMappingURL=catalogs.service.js.map \ No newline at end of file diff --git a/dist/catalogs/catalogs.service.js.map b/dist/catalogs/catalogs.service.js.map new file mode 100644 index 0000000..580804d --- /dev/null +++ b/dist/catalogs/catalogs.service.js.map @@ -0,0 +1 @@ +{"version":3,"file":"catalogs.service.js","sourceRoot":"","sources":["../../src/catalogs/catalogs.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAIwB;AACxB,2CAAwC;AACxC,6DAAyD;AAIlD,IAAM,eAAe,GAArB,MAAM,eAAe;IACG;IAA7B,YAA6B,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;IAEtD,KAAK,CAAC,OAAO,CAAC,SAAkB,EAAE,UAAU,GAAG,KAAK;QAClD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC;YAClD,KAAK,EAAE;gBACL,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CA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,QAAQ,EAAE,IAAI,EAAE,EAAE;aACvC;SACF,CAAC,CAAC;QACH,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAEO,KAAK,CAAC,MAAM,CAAC,EAAU;QAC7B,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;QACxE,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,0BAAiB,CAAC,kBAAkB,CAAC,CAAC;QAC9D,OAAO,OAAO,CAAC;IACjB,CAAC;IAEO,GAAG,CAAC,OAYX;QACC,OAAO;YACL,EAAE,EAAE,OAAO,CAAC,EAAE;YACd,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,WAAW,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI;YACjC,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,SAAS;YAC7C,YAAY,EAAE,OAAO,CAAC,YAAY;YAClC,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,YAAY,EAAE,OAAO,CAAC,MAAM,CAAC,QAAQ;YACrC,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,WAAW,EAAE;YAC1C,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,WAAW,EAAE;SAC3C,CAAC;IACJ,CAAC;CACF,CAAA;AAvIY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;qCAE0B,8BAAa;GADvC,eAAe,CAuI3B"} \ No newline at end of file diff --git a/dist/catalogs/dto/catalog.dto.d.ts b/dist/catalogs/dto/catalog.dto.d.ts new file mode 100644 index 0000000..1a9bb69 --- /dev/null +++ b/dist/catalogs/dto/catalog.dto.d.ts @@ -0,0 +1,18 @@ +export declare class CreateCatalogDto { + companyId: string; + name: string; + code: string; + description?: string; + displayOrder?: number; + isActive?: boolean; +} +export declare class UpdateCatalogDto { + name?: string; + code?: string; + description?: string | null; + displayOrder?: number; + isActive?: boolean; +} +export declare class SetCatalogActiveDto { + isActive: boolean; +} diff --git a/dist/catalogs/dto/catalog.dto.js b/dist/catalogs/dto/catalog.dto.js new file mode 100644 index 0000000..4009cc5 --- /dev/null +++ b/dist/catalogs/dto/catalog.dto.js @@ -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); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.SetCatalogActiveDto = exports.UpdateCatalogDto = exports.CreateCatalogDto = void 0; +const class_validator_1 = require("class-validator"); +const class_transformer_1 = require("class-transformer"); +class CreateCatalogDto { + companyId; + name; + code; + description; + displayOrder; + isActive; +} +exports.CreateCatalogDto = CreateCatalogDto; +__decorate([ + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], CreateCatalogDto.prototype, "companyId", void 0); +__decorate([ + (0, class_validator_1.IsString)(), + (0, class_validator_1.MinLength)(1), + __metadata("design:type", String) +], CreateCatalogDto.prototype, "name", void 0); +__decorate([ + (0, class_validator_1.IsString)(), + (0, class_validator_1.MinLength)(1), + __metadata("design:type", String) +], CreateCatalogDto.prototype, "code", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], CreateCatalogDto.prototype, "description", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsInt)(), + __metadata("design:type", Number) +], CreateCatalogDto.prototype, "displayOrder", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsBoolean)(), + __metadata("design:type", Boolean) +], CreateCatalogDto.prototype, "isActive", void 0); +class UpdateCatalogDto { + name; + code; + description; + displayOrder; + isActive; +} +exports.UpdateCatalogDto = UpdateCatalogDto; +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + (0, class_validator_1.MinLength)(1), + __metadata("design:type", String) +], UpdateCatalogDto.prototype, "name", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + (0, class_validator_1.MinLength)(1), + __metadata("design:type", String) +], UpdateCatalogDto.prototype, "code", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", Object) +], UpdateCatalogDto.prototype, "description", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsInt)(), + __metadata("design:type", Number) +], UpdateCatalogDto.prototype, "displayOrder", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsBoolean)(), + __metadata("design:type", Boolean) +], UpdateCatalogDto.prototype, "isActive", void 0); +class SetCatalogActiveDto { + isActive; +} +exports.SetCatalogActiveDto = SetCatalogActiveDto; +__decorate([ + (0, class_validator_1.IsBoolean)(), + __metadata("design:type", Boolean) +], SetCatalogActiveDto.prototype, "isActive", void 0); +//# sourceMappingURL=catalog.dto.js.map \ No newline at end of file diff --git a/dist/catalogs/dto/catalog.dto.js.map b/dist/catalogs/dto/catalog.dto.js.map new file mode 100644 index 0000000..927b28b --- /dev/null +++ b/dist/catalogs/dto/catalog.dto.js.map @@ -0,0 +1 @@ +{"version":3,"file":"catalog.dto.js","sourceRoot":"","sources":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E;IACZ,IAAA,2BAAS,GAAE;;kDACO;AAGrB,MAAa,mBAAmB;IAE9B,QAAQ,CAAW;CACpB;AAHD,kDAGC;AADC;IADC,IAAA,2BAAS,GAAE;;qDACO"} \ No newline at end of file diff --git a/dist/checks/checks.controller.d.ts b/dist/checks/checks.controller.d.ts new file mode 100644 index 0000000..1c26ab5 --- /dev/null +++ b/dist/checks/checks.controller.d.ts @@ -0,0 +1,49 @@ +import { ChecksService } from './checks.service'; +import type { AuthPrincipal } from '../common/decorators/current-user.decorator'; +import { UpdateCheckStatusDto } from './dto/check.dto'; +export declare class ChecksController { + private readonly checksService; + constructor(checksService: ChecksService); + findByOrder(orderId: string): Promise<{ + id: string; + orderId: string; + row: number; + amount: number; + dueDate: string; + sayadId: string; + checkNumber: string | undefined; + ownerNationalId: string | undefined; + ownerFirstName: string | undefined; + ownerLastName: string | undefined; + bankName: string; + branchName: string | undefined; + frontImage: string | undefined; + backImage: string | undefined; + notes: string | undefined; + mode: string; + status: import("@prisma/client").$Enums.CheckStatus; + createdAt: string; + updatedAt: string; + }[]>; + updateStatus(user: AuthPrincipal, id: string, dto: UpdateCheckStatusDto): Promise<{ + id: string; + orderId: string; + row: number; + amount: number; + dueDate: string; + sayadId: string; + checkNumber: string | undefined; + ownerNationalId: string | undefined; + ownerFirstName: string | undefined; + ownerLastName: string | undefined; + bankName: string; + branchName: string | undefined; + frontImage: string | undefined; + backImage: string | undefined; + notes: string | undefined; + mode: string; + status: import("@prisma/client").$Enums.CheckStatus; + createdAt: string; + updatedAt: string; + }>; +} diff --git a/dist/checks/checks.controller.js b/dist/checks/checks.controller.js new file mode 100644 index 0000000..8f9d21d --- /dev/null +++ b/dist/checks/checks.controller.js @@ -0,0 +1,55 @@ +"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.ChecksController = void 0; +const common_1 = require("@nestjs/common"); +const checks_service_1 = require("./checks.service"); +const auth_decorators_1 = require("../common/decorators/auth.decorators"); +const current_user_decorator_1 = require("../common/decorators/current-user.decorator"); +const check_dto_1 = require("./dto/check.dto"); +let ChecksController = class ChecksController { + checksService; + constructor(checksService) { + this.checksService = checksService; + } + findByOrder(orderId) { + return this.checksService.findByOrder(orderId); + } + updateStatus(user, id, dto) { + return this.checksService.updateStatus(id, user.id, dto); + } +}; +exports.ChecksController = ChecksController; +__decorate([ + (0, common_1.Get)('admin/orders/:orderId/checks'), + __param(0, (0, common_1.Param)('orderId')), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String]), + __metadata("design:returntype", void 0) +], ChecksController.prototype, "findByOrder", null); +__decorate([ + (0, common_1.Patch)('admin/checks/:id/status'), + __param(0, (0, current_user_decorator_1.CurrentUser)()), + __param(1, (0, common_1.Param)('id')), + __param(2, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [Object, String, check_dto_1.UpdateCheckStatusDto]), + __metadata("design:returntype", void 0) +], ChecksController.prototype, "updateStatus", null); +exports.ChecksController = ChecksController = __decorate([ + (0, common_1.Controller)(), + (0, auth_decorators_1.AuthType)('admin'), + __metadata("design:paramtypes", [checks_service_1.ChecksService]) +], ChecksController); +//# sourceMappingURL=checks.controller.js.map \ No newline at end of file diff --git a/dist/checks/checks.controller.js.map b/dist/checks/checks.controller.js.map new file mode 100644 index 0000000..07d9887 --- /dev/null +++ b/dist/checks/checks.controller.js.map @@ -0,0 +1 @@ +{"version":3,"file":"checks.controller.js","sourceRoot":"","sources":["../../src/checks/checks.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAqE;AACrE,qDAAiD;AACjD,0EAAgE;AAChE,wFAA0E;AAE1E,+CAAuD;AAIhD,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IACE;IAA7B,YAA6B,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;IAAG,CAAC;IAG7D,WAAW,CAAmB,OAAe;QAC3C,OAAO,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACjD,CAAC;IAGD,YAAY,CACK,IAAmB,EACrB,EAAU,EACf,GAAyB;QAEjC,OAAO,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IAC3D,CAAC;CACF,CAAA;AAhBY,4CAAgB;AAI3B;IADC,IAAA,YAAG,EAAC,8BAA8B,CAAC;IACvB,WAAA,IAAA,cAAK,EAAC,SAAS,CAAC,CAAA;;;;mDAE5B;AAGD;IADC,IAAA,cAAK,EAAC,yBAAyB,CAAC;IAE9B,WAAA,IAAA,oCAAW,GAAE,CAAA;IACb,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;IACX,WAAA,IAAA,aAAI,GAAE,CAAA;;qDAAM,gCAAoB;;oDAGlC;2BAfU,gBAAgB;IAF5B,IAAA,mBAAU,GAAE;IACZ,IAAA,0BAAQ,EAAC,OAAO,CAAC;qCAE4B,8BAAa;GAD9C,gBAAgB,CAgB5B"} \ No newline at end of file diff --git a/dist/checks/checks.module.d.ts b/dist/checks/checks.module.d.ts new file mode 100644 index 0000000..3a0ec12 --- /dev/null +++ b/dist/checks/checks.module.d.ts @@ -0,0 +1,2 @@ +export declare class ChecksModule { +} diff --git a/dist/checks/checks.module.js b/dist/checks/checks.module.js new file mode 100644 index 0000000..7ef7a2d --- /dev/null +++ b/dist/checks/checks.module.js @@ -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.ChecksModule = void 0; +const common_1 = require("@nestjs/common"); +const checks_controller_1 = require("./checks.controller"); +const checks_service_1 = require("./checks.service"); +let ChecksModule = class ChecksModule { +}; +exports.ChecksModule = ChecksModule; +exports.ChecksModule = ChecksModule = __decorate([ + (0, common_1.Module)({ + controllers: [checks_controller_1.ChecksController], + providers: [checks_service_1.ChecksService], + exports: [checks_service_1.ChecksService], + }) +], ChecksModule); +//# sourceMappingURL=checks.module.js.map \ No newline at end of file diff --git a/dist/checks/checks.module.js.map b/dist/checks/checks.module.js.map new file mode 100644 index 0000000..95e8e97 --- /dev/null +++ b/dist/checks/checks.module.js.map @@ -0,0 +1 @@ +{"version":3,"file":"checks.module.js","sourceRoot":"","sources":["../../src/checks/checks.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,2DAAuD;AACvD,qDAAiD;AAO1C,IAAM,YAAY,GAAlB,MAAM,YAAY;CAAG,CAAA;AAAf,oCAAY;uBAAZ,YAAY;IALxB,IAAA,eAAM,EAAC;QACN,WAAW,EAAE,CAAC,oCAAgB,CAAC;QAC/B,SAAS,EAAE,CAAC,8BAAa,CAAC;QAC1B,OAAO,EAAE,CAAC,8BAAa,CAAC;KACzB,CAAC;GACW,YAAY,CAAG"} \ No newline at end of file diff --git a/dist/checks/checks.service.d.ts b/dist/checks/checks.service.d.ts new file mode 100644 index 0000000..42453a4 --- /dev/null +++ b/dist/checks/checks.service.d.ts @@ -0,0 +1,49 @@ +import { PrismaService } from '../prisma/prisma.service'; +import { UpdateCheckStatusDto } from './dto/check.dto'; +export declare class ChecksService { + private readonly prisma; + constructor(prisma: PrismaService); + findByOrder(orderId: string): Promise<{ + id: string; + orderId: string; + row: number; + amount: number; + dueDate: string; + sayadId: string; + checkNumber: string | undefined; + ownerNationalId: string | undefined; + ownerFirstName: string | undefined; + ownerLastName: string | undefined; + bankName: string; + branchName: string | undefined; + frontImage: string | undefined; + backImage: string | undefined; + notes: string | undefined; + mode: string; + status: import("@prisma/client").$Enums.CheckStatus; + createdAt: string; + updatedAt: string; + }[]>; + updateStatus(id: string, adminId: string, dto: UpdateCheckStatusDto): Promise<{ + id: string; + orderId: string; + row: number; + amount: number; + dueDate: string; + sayadId: string; + checkNumber: string | undefined; + ownerNationalId: string | undefined; + ownerFirstName: string | undefined; + ownerLastName: string | undefined; + bankName: string; + branchName: string | undefined; + frontImage: string | undefined; + backImage: string | undefined; + notes: string | undefined; + mode: string; + status: import("@prisma/client").$Enums.CheckStatus; + createdAt: string; + updatedAt: string; + }>; + private map; +} diff --git a/dist/checks/checks.service.js b/dist/checks/checks.service.js new file mode 100644 index 0000000..13ab3d5 --- /dev/null +++ b/dist/checks/checks.service.js @@ -0,0 +1,109 @@ +"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.ChecksService = void 0; +const common_1 = require("@nestjs/common"); +const client_1 = require("@prisma/client"); +const prisma_service_1 = require("../prisma/prisma.service"); +let ChecksService = class ChecksService { + prisma; + constructor(prisma) { + this.prisma = prisma; + } + async findByOrder(orderId) { + const order = await this.prisma.order.findUnique({ where: { id: orderId } }); + if (!order) + throw new common_1.NotFoundException('سفارش یافت نشد'); + const checks = await this.prisma.check.findMany({ + where: { orderId }, + orderBy: { row: 'asc' }, + }); + return checks.map((c) => this.map(c)); + } + async updateStatus(id, adminId, dto) { + const check = await this.prisma.check.findUnique({ + where: { id }, + include: { order: { include: { checks: true } } }, + }); + if (!check) + throw new common_1.NotFoundException('چک یافت نشد'); + const updated = await this.prisma.$transaction(async (tx) => { + const result = await tx.check.update({ + where: { id }, + data: { + status: dto.status, + notes: dto.note + ? [check.notes, dto.note].filter(Boolean).join('\n') + : check.notes, + }, + }); + const siblings = await tx.check.findMany({ where: { orderId: check.orderId } }); + const allApproved = siblings.every((c) => c.status === client_1.CheckStatus.approved); + const anyRejected = siblings.some((c) => c.status === client_1.CheckStatus.rejected); + let nextStatus = null; + if (anyRejected) { + nextStatus = client_1.OrderStatus.check_rejected; + } + else if (allApproved) { + nextStatus = client_1.OrderStatus.checks_approved; + } + else if (dto.status === client_1.CheckStatus.rejected) { + nextStatus = client_1.OrderStatus.check_needs_fix; + } + if (nextStatus && nextStatus !== check.order.status) { + await tx.order.update({ + where: { id: check.orderId }, + data: { status: nextStatus }, + }); + await tx.orderStatusHistory.create({ + data: { + orderId: check.orderId, + fromStatus: check.order.status, + toStatus: nextStatus, + changedBy: `admin:${adminId}`, + note: dto.note || `وضعیت چک به ${dto.status} تغییر کرد`, + }, + }); + } + return result; + }); + return this.map(updated); + } + map(c) { + return { + id: c.id, + orderId: c.orderId, + row: c.row, + amount: c.amount, + dueDate: c.dueDate.toISOString(), + sayadId: c.sayadId ?? '', + checkNumber: c.checkNumber ?? undefined, + ownerNationalId: c.ownerNationalId ?? undefined, + ownerFirstName: c.ownerFirstName ?? undefined, + ownerLastName: c.ownerLastName ?? undefined, + bankName: c.bankName ?? '', + branchName: c.branchName ?? undefined, + frontImage: c.frontImage ?? undefined, + backImage: c.backImage ?? undefined, + notes: c.notes ?? undefined, + mode: c.mode, + status: c.status, + createdAt: c.createdAt.toISOString(), + updatedAt: c.updatedAt.toISOString(), + }; + } +}; +exports.ChecksService = ChecksService; +exports.ChecksService = ChecksService = __decorate([ + (0, common_1.Injectable)(), + __metadata("design:paramtypes", [prisma_service_1.PrismaService]) +], ChecksService); +//# sourceMappingURL=checks.service.js.map \ No newline at end of file diff --git a/dist/checks/checks.service.js.map b/dist/checks/checks.service.js.map new file mode 100644 index 0000000..e8337d2 --- /dev/null +++ b/dist/checks/checks.service.js.map @@ -0,0 +1 @@ +{"version":3,"file":"checks.service.js","sourceRoot":"","sources":["../../src/checks/checks.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAGwB;AACxB,2CAGwB;AACxB,6DAAyD;AAIlD,IAAM,aAAa,GAAnB,MAAM,aAAa;IACK;IAA7B,YAA6B,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;IAEtD,KAAK,CAAC,WAAW,CAAC,OAAe;QAC/B,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;QAC7E,IAAI,CAAC,KAAK;YAAE,MAAM,IAAI,0BAAiB,CAAC,gBAAgB,CAAC,CAAC;QAE1D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC;YAC9C,KAAK,EAAE,EAAE,OAAO,EAAE;YAClB,OAAO,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE;SACxB,CAAC,CAAC;QACH,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;QACC,OAAO;YACL,EAAE,EAAE,CAAC,CAAC,EAAE;YACR,OAAO,EAAE,CAAC,CAAC,OAAO;YAClB,GAAG,EAAE,CAAC,CAAC,GAAG;YACV,MAAM,EAAE,CAAC,CAAC,MAAM;YAChB,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE;YAChC,OAAO,EAAE,CAAC,CAAC,OAAO,IAAI,EAAE;YACxB,WAAW,EAAE,CAAC,CAAC,WAAW,IAAI,SAAS;YACvC,eAAe,EAAE,CAAC,CAAC,eAAe,IAAI,SAAS;YAC/C,cAAc,EAAE,CAAC,CAAC,cAAc,IAAI,SAAS;YAC7C,aAAa,EAAE,CAAC,CAAC,aAAa,IAAI,SAAS;YAC3C,QAAQ,EAAE,CAAC,CAAC,QAAQ,IAAI,EAAE;YAC1B,UAAU,EAAE,CAAC,CAAC,UAAU,IAAI,SAAS;YACrC,UAAU,EAAE,CAAC,CAAC,UAAU,IAAI,SAAS;YACrC,SAAS,EAAE,CAAC,CAAC,SAAS,IAAI,SAAS;YACnC,KAAK,EAAE,CAAC,CAAC,KAAK,IAAI,SAAS;YAC3B,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,MAAM,EAAE,CAAC,CAAC,MAAM;YAChB,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,WAAW,EAAE;YACpC,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,WAAW,EAAE;SACrC,CAAC;IACJ,CAAC;CACF,CAAA;AAlHY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;qCAE0B,8BAAa;GADvC,aAAa,CAkHzB"} \ No newline at end of file diff --git a/dist/checks/dto/check.dto.d.ts b/dist/checks/dto/check.dto.d.ts new file mode 100644 index 0000000..6e5a18c --- /dev/null +++ b/dist/checks/dto/check.dto.d.ts @@ -0,0 +1,5 @@ +import { CheckStatus } from '@prisma/client'; +export declare class UpdateCheckStatusDto { + status: CheckStatus; + note?: string; +} diff --git a/dist/checks/dto/check.dto.js b/dist/checks/dto/check.dto.js new file mode 100644 index 0000000..b6e762e --- /dev/null +++ b/dist/checks/dto/check.dto.js @@ -0,0 +1,29 @@ +"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.UpdateCheckStatusDto = void 0; +const class_validator_1 = require("class-validator"); +const client_1 = require("@prisma/client"); +class UpdateCheckStatusDto { + status; + note; +} +exports.UpdateCheckStatusDto = UpdateCheckStatusDto; +__decorate([ + (0, class_validator_1.IsEnum)(client_1.CheckStatus), + __metadata("design:type", String) +], UpdateCheckStatusDto.prototype, "status", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], UpdateCheckStatusDto.prototype, "note", void 0); +//# sourceMappingURL=check.dto.js.map \ No newline at end of file diff --git a/dist/checks/dto/check.dto.js.map b/dist/checks/dto/check.dto.js.map new file mode 100644 index 0000000..91d3a98 --- /dev/null +++ b/dist/checks/dto/check.dto.js.map @@ -0,0 +1 @@ +{"version":3,"file":"check.dto.js","sourceRoot":"","sources":["../../../src/checks/dto/check.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAA+D;AAC/D,2CAA6C;AAE7C,MAAa,oBAAoB;IAE/B,MAAM,CAAe;IAIrB,IAAI,CAAU;CACf;AAPD,oDAOC;AALC;IADC,IAAA,wBAAM,EAAC,oBAAW,CAAC;;oDACC;AAIrB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;kDACG"} \ No newline at end of file diff --git a/dist/common/decorators/auth.decorators.d.ts b/dist/common/decorators/auth.decorators.d.ts new file mode 100644 index 0000000..7d10943 --- /dev/null +++ b/dist/common/decorators/auth.decorators.d.ts @@ -0,0 +1,6 @@ +export declare const IS_PUBLIC_KEY = "isPublic"; +export declare const Public: () => import("@nestjs/common").CustomDecorator; +export declare const ROLES_KEY = "roles"; +export declare const Roles: (...roles: string[]) => import("@nestjs/common").CustomDecorator; +export declare const AUTH_TYPE_KEY = "authType"; +export declare const AuthType: (type: "customer" | "admin" | "any") => import("@nestjs/common").CustomDecorator; diff --git a/dist/common/decorators/auth.decorators.js b/dist/common/decorators/auth.decorators.js new file mode 100644 index 0000000..fb35f86 --- /dev/null +++ b/dist/common/decorators/auth.decorators.js @@ -0,0 +1,14 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.AuthType = exports.AUTH_TYPE_KEY = exports.Roles = exports.ROLES_KEY = exports.Public = exports.IS_PUBLIC_KEY = void 0; +const common_1 = require("@nestjs/common"); +exports.IS_PUBLIC_KEY = 'isPublic'; +const Public = () => (0, common_1.SetMetadata)(exports.IS_PUBLIC_KEY, true); +exports.Public = Public; +exports.ROLES_KEY = 'roles'; +const Roles = (...roles) => (0, common_1.SetMetadata)(exports.ROLES_KEY, roles); +exports.Roles = Roles; +exports.AUTH_TYPE_KEY = 'authType'; +const AuthType = (type) => (0, common_1.SetMetadata)(exports.AUTH_TYPE_KEY, type); +exports.AuthType = AuthType; +//# sourceMappingURL=auth.decorators.js.map \ No newline at end of file diff --git a/dist/common/decorators/auth.decorators.js.map b/dist/common/decorators/auth.decorators.js.map new file mode 100644 index 0000000..1c9854a --- /dev/null +++ b/dist/common/decorators/auth.decorators.js.map @@ -0,0 +1 @@ +{"version":3,"file":"auth.decorators.js","sourceRoot":"","sources":["../../../src/common/decorators/auth.decorators.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAEhC,QAAA,aAAa,GAAG,UAAU,CAAC;AACjC,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,IAAA,oBAAW,EAAC,qBAAa,EAAE,IAAI,CAAC,CAAC;AAAhD,QAAA,MAAM,UAA0C;AAEhD,QAAA,SAAS,GAAG,OAAO,CAAC;AAC1B,MAAM,KAAK,GAAG,CAAC,GAAG,KAAe,EAAE,EAAE,CAAC,IAAA,oBAAW,EAAC,iBAAS,EAAE,KAAK,CAAC,CAAC;AAA9D,QAAA,KAAK,SAAyD;AAE9D,QAAA,aAAa,GAAG,UAAU,CAAC;AACjC,MAAM,QAAQ,GAAG,CAAC,IAAkC,EAAE,EAAE,CAC7D,IAAA,oBAAW,EAAC,qBAAa,EAAE,IAAI,CAAC,CAAC;AADtB,QAAA,QAAQ,YACc"} \ No newline at end of file diff --git a/dist/common/decorators/current-user.decorator.d.ts b/dist/common/decorators/current-user.decorator.d.ts new file mode 100644 index 0000000..9acbe07 --- /dev/null +++ b/dist/common/decorators/current-user.decorator.d.ts @@ -0,0 +1,7 @@ +export interface AuthPrincipal { + id: string; + type: 'customer' | 'admin'; + role?: string; + phone?: string; +} +export declare const CurrentUser: (...dataOrPipes: unknown[]) => ParameterDecorator; diff --git a/dist/common/decorators/current-user.decorator.js b/dist/common/decorators/current-user.decorator.js new file mode 100644 index 0000000..35d1f32 --- /dev/null +++ b/dist/common/decorators/current-user.decorator.js @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.CurrentUser = void 0; +const common_1 = require("@nestjs/common"); +exports.CurrentUser = (0, common_1.createParamDecorator)((_data, ctx) => { + const request = ctx.switchToHttp().getRequest(); + return request.user; +}); +//# sourceMappingURL=current-user.decorator.js.map \ No newline at end of file diff --git a/dist/common/decorators/current-user.decorator.js.map b/dist/common/decorators/current-user.decorator.js.map new file mode 100644 index 0000000..2b37eec --- /dev/null +++ b/dist/common/decorators/current-user.decorator.js.map @@ -0,0 +1 @@ +{"version":3,"file":"current-user.decorator.js","sourceRoot":"","sources":["../../../src/common/decorators/current-user.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAAwE;AAS3D,QAAA,WAAW,GAAG,IAAA,6BAAoB,EAC7C,CAAC,KAAc,EAAE,GAAqB,EAAiB,EAAE;IACvD,MAAM,OAAO,GAAG,GAAG,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;IAChD,OAAO,OAAO,CAAC,IAAI,CAAC;AACtB,CAAC,CACF,CAAC"} \ No newline at end of file diff --git a/dist/common/guards/jwt-auth.guard.d.ts b/dist/common/guards/jwt-auth.guard.d.ts new file mode 100644 index 0000000..43386d5 --- /dev/null +++ b/dist/common/guards/jwt-auth.guard.d.ts @@ -0,0 +1,11 @@ +import { CanActivate, ExecutionContext } from '@nestjs/common'; +import { Reflector } from '@nestjs/core'; +import { JwtService } from '@nestjs/jwt'; +import { ConfigService } from '@nestjs/config'; +export declare class JwtAuthGuard implements CanActivate { + private readonly reflector; + private readonly jwtService; + private readonly config; + constructor(reflector: Reflector, jwtService: JwtService, config: ConfigService); + canActivate(context: ExecutionContext): Promise; +} diff --git a/dist/common/guards/jwt-auth.guard.js b/dist/common/guards/jwt-auth.guard.js new file mode 100644 index 0000000..07f257e --- /dev/null +++ b/dist/common/guards/jwt-auth.guard.js @@ -0,0 +1,77 @@ +"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.JwtAuthGuard = void 0; +const common_1 = require("@nestjs/common"); +const core_1 = require("@nestjs/core"); +const jwt_1 = require("@nestjs/jwt"); +const config_1 = require("@nestjs/config"); +const auth_decorators_1 = require("../decorators/auth.decorators"); +let JwtAuthGuard = class JwtAuthGuard { + reflector; + jwtService; + config; + constructor(reflector, jwtService, config) { + this.reflector = reflector; + this.jwtService = jwtService; + this.config = config; + } + async canActivate(context) { + const isPublic = this.reflector.getAllAndOverride(auth_decorators_1.IS_PUBLIC_KEY, [ + context.getHandler(), + context.getClass(), + ]); + if (isPublic) + return true; + const request = context.switchToHttp().getRequest(); + const authHeader = request.headers.authorization; + if (!authHeader?.startsWith('Bearer ')) { + throw new common_1.UnauthorizedException('توکن احراز هویت الزامی است'); + } + const token = authHeader.slice(7); + let payload; + try { + payload = await this.jwtService.verifyAsync(token, { + secret: this.config.get('JWT_SECRET'), + }); + } + catch { + throw new common_1.UnauthorizedException('توکن نامعتبر یا منقضی شده است'); + } + const user = { + id: payload.sub ?? payload.id, + type: payload.type, + role: payload.role, + phone: payload.phone, + }; + request.user = user; + const authType = this.reflector.getAllAndOverride(auth_decorators_1.AUTH_TYPE_KEY, [context.getHandler(), context.getClass()]); + if (authType && authType !== 'any' && user.type !== authType) { + throw new common_1.ForbiddenException('دسترسی مجاز نیست'); + } + const roles = this.reflector.getAllAndOverride(auth_decorators_1.ROLES_KEY, [ + context.getHandler(), + context.getClass(), + ]); + if (roles?.length && (!user.role || !roles.includes(user.role))) { + throw new common_1.ForbiddenException('نقش کاربری کافی نیست'); + } + return true; + } +}; +exports.JwtAuthGuard = JwtAuthGuard; +exports.JwtAuthGuard = JwtAuthGuard = __decorate([ + (0, common_1.Injectable)(), + __metadata("design:paramtypes", [core_1.Reflector, + jwt_1.JwtService, + config_1.ConfigService]) +], JwtAuthGuard); +//# sourceMappingURL=jwt-auth.guard.js.map \ No newline at end of file diff --git a/dist/common/guards/jwt-auth.guard.js.map b/dist/common/guards/jwt-auth.guard.js.map new file mode 100644 index 0000000..0390e3c --- /dev/null +++ b/dist/common/guards/jwt-auth.guard.js.map @@ -0,0 +1 @@ +{"version":3,"file":"jwt-auth.guard.js","sourceRoot":"","sources":["../../../src/common/guards/jwt-auth.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAMwB;AACxB,uCAAyC;AACzC,qCAAyC;AACzC,2CAA+C;AAC/C,mEAIuC;AAIhC,IAAM,YAAY,GAAlB,MAAM,YAAY;IAEJ;IACA;IACA;IAHnB,YACmB,SAAoB,EACpB,UAAsB,EACtB,MAAqB;QAFrB,cAAS,GAAT,SAAS,CAAW;QACpB,eAAU,GAAV,UAAU,CAAY;QACtB,WAAM,GAAN,MAAM,CAAe;IACrC,CAAC;IAEJ,KAAK,CAAC,WAAW,CAAC,OAAyB;QACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAU,+BAAa,EAAE;YACxE,OAAO,CAAC,UAAU,EAAE;YACpB,OAAO,CAAC,QAAQ,EAAE;SACnB,CAAC,CAAC;QACH,IAAI,QAAQ;YAAE,OAAO,IAAI,CAAC;QAE1B,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;QACpD,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,aAAmC,CAAC;QACvE,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;YACvC,MAAM,IAAI,8BAAqB,CAAC,4BAA4B,CAAC,CAAC;QAChE,CAAC;QAED,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAClC,IAAI,OAAyC,CAAC;QAC9C,IAAI,CAAC;YACH,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,KAAK,EAAE;gBACjD,MAAM,EAAE,IAAI,CAAC,MAAM,C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\ No newline at end of file diff --git a/dist/common/utils/cash-expiry.d.ts b/dist/common/utils/cash-expiry.d.ts new file mode 100644 index 0000000..af11dcf --- /dev/null +++ b/dist/common/utils/cash-expiry.d.ts @@ -0,0 +1,4 @@ +export declare function computeCashInvoiceExpiry(company: { + cashInvoiceValidUntilHour: number | null; + cashInvoiceValidityHours: number; +}): Date; diff --git a/dist/common/utils/cash-expiry.js b/dist/common/utils/cash-expiry.js new file mode 100644 index 0000000..7dfb758 --- /dev/null +++ b/dist/common/utils/cash-expiry.js @@ -0,0 +1,17 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.computeCashInvoiceExpiry = computeCashInvoiceExpiry; +function computeCashInvoiceExpiry(company) { + const now = new Date(); + if (company.cashInvoiceValidUntilHour != null && + Number.isFinite(company.cashInvoiceValidUntilHour)) { + const expires = new Date(now); + expires.setHours(company.cashInvoiceValidUntilHour, 0, 0, 0); + if (expires.getTime() <= now.getTime()) { + expires.setDate(expires.getDate() + 1); + } + return expires; + } + return new Date(now.getTime() + company.cashInvoiceValidityHours * 60 * 60 * 1000); +} +//# sourceMappingURL=cash-expiry.js.map \ No newline at end of file diff --git a/dist/common/utils/cash-expiry.js.map b/dist/common/utils/cash-expiry.js.map new file mode 100644 index 0000000..fb0ae3d --- /dev/null +++ b/dist/common/utils/cash-expiry.js.map @@ -0,0 +1 @@ +{"version":3,"file":"cash-expiry.js","sourceRoot":"","sources":["../../../src/common/utils/cash-expiry.ts"],"names":[],"mappings":";;AAAA,4DAoBC;AApBD,SAAgB,wBAAwB,CAAC,OAGxC;IACC,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,IACE,OAAO,CAAC,yBAAyB,IAAI,IAAI;QACzC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,yBAAyB,CAAC,EAClD,CAAC;QACD,MAAM,OAAO,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC;QAC9B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,yBAAyB,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAC7D,IAAI,OAAO,CAAC,OAAO,EAAE,IAAI,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC;YACvC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;QACzC,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,OAAO,IAAI,IAAI,CACb,GAAG,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,wBAAwB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAClE,CAAC;AACJ,CAAC"} \ No newline at end of file diff --git a/dist/common/utils/check-rass.d.ts b/dist/common/utils/check-rass.d.ts new file mode 100644 index 0000000..ab6cbd6 --- /dev/null +++ b/dist/common/utils/check-rass.d.ts @@ -0,0 +1,13 @@ +export type CheckRassInput = { + amount: number; + dueDate: Date | string; +}; +export type CheckRassResult = { + checkCount: number; + totalAmount: number; + nearestDueDate: string | null; + farthestDueDate: string | null; + rassDays: number; + rassDate: string | null; +}; +export declare function calculateCheckRass(checks: CheckRassInput[], baseDate?: Date): CheckRassResult; diff --git a/dist/common/utils/check-rass.js b/dist/common/utils/check-rass.js new file mode 100644 index 0000000..57c2de7 --- /dev/null +++ b/dist/common/utils/check-rass.js @@ -0,0 +1,44 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.calculateCheckRass = calculateCheckRass; +function startOfDay(date) { + const d = new Date(date); + d.setHours(0, 0, 0, 0); + return d; +} +function calculateCheckRass(checks, baseDate = new Date()) { + if (checks.length === 0) { + return { + checkCount: 0, + totalAmount: 0, + nearestDueDate: null, + farthestDueDate: null, + rassDays: 0, + rassDate: null, + }; + } + const base = startOfDay(baseDate); + let totalAmount = 0; + let weightedDays = 0; + const dueDates = []; + for (const check of checks) { + const due = startOfDay(new Date(check.dueDate)); + dueDates.push(due); + const days = Math.max(0, Math.round((due.getTime() - base.getTime()) / (1000 * 60 * 60 * 24))); + totalAmount += check.amount; + weightedDays += check.amount * days; + } + const rassDays = totalAmount > 0 ? Math.round(weightedDays / totalAmount) : 0; + const rassDate = new Date(base); + rassDate.setDate(rassDate.getDate() + rassDays); + dueDates.sort((a, b) => a.getTime() - b.getTime()); + return { + checkCount: checks.length, + totalAmount, + nearestDueDate: dueDates[0]?.toISOString() ?? null, + farthestDueDate: dueDates[dueDates.length - 1]?.toISOString() ?? null, + rassDays, + rassDate: rassDate.toISOString(), + }; +} +//# sourceMappingURL=check-rass.js.map \ No newline at end of file diff --git a/dist/common/utils/check-rass.js.map b/dist/common/utils/check-rass.js.map new file mode 100644 index 0000000..1a935a9 --- /dev/null +++ b/dist/common/utils/check-rass.js.map @@ -0,0 +1 @@ +{"version":3,"file":"check-rass.js","sourceRoot":"","sources":["../../../src/common/utils/check-rass.ts"],"names":[],"mappings":";;AAoBA,gDA4CC;AAlDD,SAAS,UAAU,CAAC,IAAU;IAC5B,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACvB,OAAO,CAAC,CAAC;AACX,CAAC;AAED,SAAgB,kBAAkB,CAChC,MAAwB,EACxB,WAAiB,IAAI,IAAI,EAAE;IAE3B,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO;YACL,UAAU,EAAE,CAAC;YACb,WAAW,EAAE,CAAC;YACd,cAAc,EAAE,IAAI;YACpB,eAAe,EAAE,IAAI;YACrB,QAAQ,EAAE,CAAC;YACX,QAAQ,EAAE,IAAI;SACf,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;IAClC,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,IAAI,YAAY,GAAG,CAAC,CAAC;IACrB,MAAM,QAAQ,GAAW,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AC,WAAW,EAAE;KACjC,CAAC;AACJ,CAAC"} \ No newline at end of file diff --git a/dist/common/utils/name.d.ts b/dist/common/utils/name.d.ts new file mode 100644 index 0000000..06b809b --- /dev/null +++ b/dist/common/utils/name.d.ts @@ -0,0 +1,5 @@ +export declare function splitFullName(name: string): { + firstName: string; + lastName: string; +}; +export declare function joinFullName(firstName: string, lastName: string): string; diff --git a/dist/common/utils/name.js b/dist/common/utils/name.js new file mode 100644 index 0000000..c8c4c57 --- /dev/null +++ b/dist/common/utils/name.js @@ -0,0 +1,22 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.splitFullName = splitFullName; +exports.joinFullName = joinFullName; +function splitFullName(name) { + const trimmed = name.trim().replace(/\s+/g, ' '); + if (!trimmed) { + return { firstName: 'مشتری', lastName: 'جدید' }; + } + const parts = trimmed.split(' '); + if (parts.length === 1) { + return { firstName: parts[0], lastName: '' }; + } + return { + firstName: parts[0], + lastName: parts.slice(1).join(' '), + }; +} +function joinFullName(firstName, lastName) { + return `${firstName} ${lastName}`.trim(); +} +//# sourceMappingURL=name.js.map \ No newline at end of file diff --git a/dist/common/utils/name.js.map b/dist/common/utils/name.js.map new file mode 100644 index 0000000..0fb298a --- /dev/null +++ b/dist/common/utils/name.js.map @@ -0,0 +1 @@ +{"version":3,"file":"name.js","sourceRoot":"","sources":["../../../src/common/utils/name.ts"],"names":[],"mappings":";;AAAA,sCAgBC;AAED,oCAEC;AApBD,SAAgB,aAAa,CAAC,IAAY;IAIxC,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACjD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;IAClD,CAAC;IACD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACjC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IAChD,CAAC;IACD,OAAO;QACL,SAAS,EAAE,KAAK,CAAC,CAAC,CAAE;QACpB,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;KACnC,CAAC;AACJ,CAAC;AAED,SAAgB,YAAY,CAAC,SAAiB,EAAE,QAAgB;IAC9D,OAAO,GAAG,SAAS,IAAI,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC;AAC3C,CAAC"} \ No newline at end of file diff --git a/dist/common/utils/order-number.d.ts b/dist/common/utils/order-number.d.ts new file mode 100644 index 0000000..8e3c990 --- /dev/null +++ b/dist/common/utils/order-number.d.ts @@ -0,0 +1 @@ +export declare function generateOrderNumber(date?: Date): string; diff --git a/dist/common/utils/order-number.js b/dist/common/utils/order-number.js new file mode 100644 index 0000000..4ae9022 --- /dev/null +++ b/dist/common/utils/order-number.js @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.generateOrderNumber = generateOrderNumber; +function generateOrderNumber(date = new Date()) { + const year = new Intl.DateTimeFormat('fa-IR-u-ca-persian', { + year: 'numeric', + }).format(date); + const persianYear = year.replace(/[^\d]/g, '') || '1403'; + const seq = Math.floor(Math.random() * 9000) + 1000; + return `ORD-${persianYear}-${seq}`; +} +//# sourceMappingURL=order-number.js.map \ No newline at end of file diff --git a/dist/common/utils/order-number.js.map b/dist/common/utils/order-number.js.map new file mode 100644 index 0000000..7514fbc --- /dev/null +++ b/dist/common/utils/order-number.js.map @@ -0,0 +1 @@ +{"version":3,"file":"order-number.js","sourceRoot":"","sources":["../../../src/common/utils/order-number.ts"],"names":[],"mappings":";;AAAA,kDAOC;AAPD,SAAgB,mBAAmB,CAAC,OAAa,IAAI,IAAI,EAAE;IACzD,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,oBAAoB,EAAE;QACzD,IAAI,EAAE,SAAS;KAChB,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAChB,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC;IACzD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IACpD,OAAO,OAAO,WAAW,IAAI,GAAG,EAAE,CAAC;AACrC,CAAC"} \ No newline at end of file diff --git a/dist/common/utils/order-status.d.ts b/dist/common/utils/order-status.d.ts new file mode 100644 index 0000000..65e8216 --- /dev/null +++ b/dist/common/utils/order-status.d.ts @@ -0,0 +1,5 @@ +import { OrderStatus } from '@prisma/client'; +export declare const ADMIN_STATUS_MAP: Record; +export declare function resolveAdminStatusFilter(status?: string): OrderStatus[] | undefined; +export declare function toAdminStatus(status: OrderStatus): string; +export declare const ORDER_STATUS_LABELS: Record; diff --git a/dist/common/utils/order-status.js b/dist/common/utils/order-status.js new file mode 100644 index 0000000..62309c9 --- /dev/null +++ b/dist/common/utils/order-status.js @@ -0,0 +1,65 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ORDER_STATUS_LABELS = exports.ADMIN_STATUS_MAP = void 0; +exports.resolveAdminStatusFilter = resolveAdminStatusFilter; +exports.toAdminStatus = toAdminStatus; +const client_1 = require("@prisma/client"); +exports.ADMIN_STATUS_MAP = { + pending_review: [client_1.OrderStatus.awaiting_review, client_1.OrderStatus.pricing], + pending_check: [client_1.OrderStatus.awaiting_check_review], + needs_correction: [client_1.OrderStatus.needs_correction], + check_correction: [client_1.OrderStatus.check_needs_fix], + final_approval: [ + client_1.OrderStatus.final_approved, + client_1.OrderStatus.checks_approved, + client_1.OrderStatus.cash_confirmed, + ], + shipped: [client_1.OrderStatus.shipped], + delivered: [client_1.OrderStatus.delivered], +}; +function resolveAdminStatusFilter(status) { + if (!status) + return undefined; + if (exports.ADMIN_STATUS_MAP[status]) + return exports.ADMIN_STATUS_MAP[status]; + if (Object.values(client_1.OrderStatus).includes(status)) { + return [status]; + } + return undefined; +} +function toAdminStatus(status) { + for (const [admin, list] of Object.entries(exports.ADMIN_STATUS_MAP)) { + if (list.includes(status)) + return admin; + } + return status; +} +exports.ORDER_STATUS_LABELS = { + cart: 'سبد خرید', + awaiting_settlement: 'در انتظار تسویه', + cash_in_progress: 'در حال ثبت نقدی', + check_in_progress: 'در حال ثبت چک', + submitted: 'ثبت‌شده', + awaiting_review: 'در انتظار بررسی', + pricing: 'قیمت‌گذاری', + needs_correction: 'نیاز به اصلاح', + awaiting_settlement_fix: 'اصلاح تسویه', + cash_invoice_issued: 'صدور فاکتور نقدی', + awaiting_cash_payment: 'در انتظار پرداخت نقدی', + cash_payment_submitted: 'رسید نقدی ارسال‌شده', + awaiting_cash_confirmation: 'تأیید پرداخت نقدی', + cash_confirmed: 'پرداخت نقدی تأیید شد', + awaiting_check_review: 'بررسی چک', + check_needs_fix: 'اصلاح چک', + check_rejected: 'رد چک', + checks_approved: 'تأیید چک‌ها', + final_approved: 'تأیید نهایی', + preparing: 'آماده‌سازی', + ready_to_ship: 'آماده ارسال', + shipped: 'ارسال‌شده', + delivered: 'تحویل‌شده', + cancelled: 'لغو شده', + rejected: 'رد شده', + expired: 'منقضی', +}; +//# sourceMappingURL=order-status.js.map \ No newline at end of file diff --git a/dist/common/utils/order-status.js.map b/dist/common/utils/order-status.js.map new file mode 100644 index 0000000..cad6ad9 --- /dev/null +++ b/dist/common/utils/order-status.js.map @@ -0,0 +1 @@ +{"version":3,"file":"order-status.js","sourceRoot":"","sources":["../../../src/common/utils/order-status.ts"],"names":[],"mappings":";;;AAiBA,4DASC;AAED,sCAKC;AAjCD,2CAA6C;AAGhC,QAAA,gBAAgB,GAAkC;IAC7D,cAAc,EAAE,CAAC,o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,YAAY;IACrB,gBAAgB,EAAE,eAAe;IACjC,uBAAuB,EAAE,aAAa;IACtC,mBAAmB,EAAE,kBAAkB;IACvC,qBAAqB,EAAE,uBAAuB;IAC9C,sBAAsB,EAAE,qBAAqB;IAC7C,0BAA0B,EAAE,mBAAmB;IAC/C,cAAc,EAAE,sBAAsB;IACtC,qBAAqB,EAAE,UAAU;IACjC,eAAe,EAAE,UAAU;IAC3B,cAAc,EAAE,OAAO;IACvB,eAAe,EAAE,aAAa;IAC9B,cAAc,EAAE,aAAa;IAC7B,SAAS,EAAE,YAAY;IACvB,aAAa,EAAE,aAAa;IAC5B,OAAO,EAAE,WAAW;IACpB,SAAS,EAAE,WAAW;IACtB,SAAS,EAAE,SAAS;IACpB,QAAQ,EAAE,QAAQ;IAClB,OAAO,EAAE,OAAO;CACjB,CAAC"} \ No newline at end of file diff --git a/dist/common/utils/phone.d.ts b/dist/common/utils/phone.d.ts new file mode 100644 index 0000000..77df04c --- /dev/null +++ b/dist/common/utils/phone.d.ts @@ -0,0 +1,3 @@ +export declare function normalizePhone(raw: string): string; +export declare function isValidPhone(phone: string): boolean; +export declare function toEnglishDigits(value: string): string; diff --git a/dist/common/utils/phone.js b/dist/common/utils/phone.js new file mode 100644 index 0000000..09b8be6 --- /dev/null +++ b/dist/common/utils/phone.js @@ -0,0 +1,24 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.normalizePhone = normalizePhone; +exports.isValidPhone = isValidPhone; +exports.toEnglishDigits = toEnglishDigits; +function normalizePhone(raw) { + let digits = raw.replace(/\D/g, ''); + if (digits.startsWith('98') && digits.length === 12) { + digits = `0${digits.slice(2)}`; + } + if (digits.length === 10 && digits.startsWith('9')) { + digits = `0${digits}`; + } + return digits; +} +function isValidPhone(phone) { + return /^09\d{9}$/.test(phone); +} +function toEnglishDigits(value) { + return value + .replace(/[۰-۹]/g, (d) => String('۰۱۲۳۴۵۶۷۸۹'.indexOf(d))) + .replace(/[٠-٩]/g, (d) => String('٠١٢٣٤٥٦٧٨٩'.indexOf(d))); +} +//# sourceMappingURL=phone.js.map \ No newline at end of file diff --git a/dist/common/utils/phone.js.map b/dist/common/utils/phone.js.map new file mode 100644 index 0000000..8375232 --- /dev/null +++ b/dist/common/utils/phone.js.map @@ -0,0 +1 @@ +{"version":3,"file":"phone.js","sourceRoot":"","sources":["../../../src/common/utils/phone.ts"],"names":[],"mappings":";;AAAA,wCASC;AAED,oCAEC;AAED,0CAIC;AAnBD,SAAgB,cAAc,CAAC,GAAW;IACxC,IAAI,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACpC,IAAI,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QACpD,MAAM,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IACjC,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,KAAK,EAAE,IAAI,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACnD,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;IACxB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAgB,YAAY,CAAC,KAAa;IACxC,OAAO,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACjC,CAAC;AAED,SAAgB,eAAe,CAAC,KAAa;IAC3C,OAAO,KAAK;SACT,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;SACzD,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/D,CAAC"} \ No newline at end of file diff --git a/dist/companies/companies.controller.d.ts b/dist/companies/companies.controller.d.ts new file mode 100644 index 0000000..6f5a0b1 --- /dev/null +++ b/dist/companies/companies.controller.d.ts @@ -0,0 +1,188 @@ +import { CompaniesService } from './companies.service'; +import { CreateBankAccountDto, CreateCompanyDto, SetActiveDto, UpdateBankAccountDto, UpdateCompanyDto } from './dto/company.dto'; +export declare class CompaniesController { + private readonly companiesService; + constructor(companiesService: CompaniesService); + findAll(activeOnly?: string): Promise<{ + id: string; + name: string; + slug: string; + description: string; + logoUrl: string | null; + logo: string | undefined; + isActive: boolean; + displayOrder: number; + maxMeteragePerInvoice: number; + cashInvoiceValidityHours: number; + cashInvoiceValidUntilHour: number | undefined; + catalogCount: number; + productCount: number; + bankAccountCount: number; + createdAt: string; + updatedAt: string; + }[]>; + findPublic(): Promise<{ + id: string; + name: string; + slug: string; + description: string; + logoUrl: string | null; + logo: string | undefined; + isActive: boolean; + displayOrder: number; + maxMeteragePerInvoice: number; + cashInvoiceValidityHours: number; + cashInvoiceValidUntilHour: number | undefined; + catalogCount: number; + productCount: number; + bankAccountCount: number; + createdAt: string; + updatedAt: string; + }[]>; + findOne(id: string): Promise<{ + bankAccounts: { + id: string; + companyId: string; + bankName: string; + accountHolder: string; + accountNumber: string; + cardNumber: string; + iban: string; + notes: string | undefined; + isActive: boolean; + displayOrder: number; + createdAt: string; + updatedAt: string; + }[]; + id: string; + name: string; + slug: string; + description: string; + logoUrl: string | null; + logo: string | undefined; + isActive: boolean; + displayOrder: number; + maxMeteragePerInvoice: number; + cashInvoiceValidityHours: number; + cashInvoiceValidUntilHour: number | undefined; + catalogCount: number; + productCount: number; + bankAccountCount: number; + createdAt: string; + updatedAt: string; + }>; + create(dto: CreateCompanyDto): Promise<{ + id: string; + name: string; + slug: string; + description: string; + logoUrl: string | null; + logo: string | undefined; + isActive: boolean; + displayOrder: number; + maxMeteragePerInvoice: number; + cashInvoiceValidityHours: number; + cashInvoiceValidUntilHour: number | undefined; + catalogCount: number; + productCount: number; + bankAccountCount: number; + createdAt: string; + updatedAt: string; + }>; + update(id: string, dto: UpdateCompanyDto): Promise<{ + id: string; + name: string; + slug: string; + description: string; + logoUrl: string | null; + logo: string | undefined; + isActive: boolean; + displayOrder: number; + maxMeteragePerInvoice: number; + cashInvoiceValidityHours: number; + cashInvoiceValidUntilHour: number | undefined; + catalogCount: number; + productCount: number; + bankAccountCount: number; + createdAt: string; + updatedAt: string; + }>; + setActive(id: string, dto: SetActiveDto): Promise<{ + id: string; + name: string; + slug: string; + description: string; + logoUrl: string | null; + logo: string | undefined; + isActive: boolean; + displayOrder: number; + maxMeteragePerInvoice: number; + cashInvoiceValidityHours: number; + cashInvoiceValidUntilHour: number | undefined; + catalogCount: number; + productCount: number; + bankAccountCount: number; + createdAt: string; + updatedAt: string; + }>; + listBankAccounts(companyId: string): Promise<{ + id: string; + companyId: string; + bankName: string; + accountHolder: string; + accountNumber: string; + cardNumber: string; + iban: string; + notes: string | undefined; + isActive: boolean; + displayOrder: number; + createdAt: string; + updatedAt: string; + }[]>; + createBankAccount(companyId: string, dto: CreateBankAccountDto): Promise<{ + id: string; + companyId: string; + bankName: string; + accountHolder: string; + accountNumber: string; + cardNumber: string; + iban: string; + notes: string | undefined; + isActive: boolean; + displayOrder: number; + createdAt: string; + updatedAt: string; + }>; +} +export declare class BankAccountsController { + private readonly companiesService; + constructor(companiesService: CompaniesService); + update(id: string, dto: UpdateBankAccountDto): Promise<{ + id: string; + companyId: string; + bankName: string; + accountHolder: string; + accountNumber: string; + cardNumber: string; + iban: string; + notes: string | undefined; + isActive: boolean; + displayOrder: number; + createdAt: string; + updatedAt: string; + }>; + setActive(id: string, dto: SetActiveDto): Promise<{ + id: string; + companyId: string; + bankName: string; + accountHolder: string; + accountNumber: string; + cardNumber: string; + iban: string; + notes: string | undefined; + isActive: boolean; + displayOrder: number; + createdAt: string; + updatedAt: string; + }>; +} diff --git a/dist/companies/companies.controller.js b/dist/companies/companies.controller.js new file mode 100644 index 0000000..10835f7 --- /dev/null +++ b/dist/companies/companies.controller.js @@ -0,0 +1,156 @@ +"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.BankAccountsController = exports.CompaniesController = void 0; +const common_1 = require("@nestjs/common"); +const companies_service_1 = require("./companies.service"); +const auth_decorators_1 = require("../common/decorators/auth.decorators"); +const company_dto_1 = require("./dto/company.dto"); +let CompaniesController = class CompaniesController { + companiesService; + constructor(companiesService) { + this.companiesService = companiesService; + } + findAll(activeOnly) { + return this.companiesService.findAll(activeOnly === 'true' || activeOnly === '1'); + } + findPublic() { + return this.companiesService.findAll(true); + } + findOne(id) { + return this.companiesService.findOne(id); + } + create(dto) { + return this.companiesService.create(dto); + } + update(id, dto) { + return this.companiesService.update(id, dto); + } + setActive(id, dto) { + return this.companiesService.setActive(id, dto.isActive); + } + listBankAccounts(companyId) { + return this.companiesService.listBankAccounts(companyId); + } + createBankAccount(companyId, dto) { + return this.companiesService.createBankAccount(companyId, dto); + } +}; +exports.CompaniesController = CompaniesController; +__decorate([ + (0, auth_decorators_1.AuthType)('any'), + (0, common_1.Get)(), + __param(0, (0, common_1.Query)('activeOnly')), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String]), + __metadata("design:returntype", void 0) +], CompaniesController.prototype, "findAll", null); +__decorate([ + (0, auth_decorators_1.Public)(), + (0, common_1.Get)('public'), + __metadata("design:type", Function), + __metadata("design:paramtypes", []), + __metadata("design:returntype", void 0) +], CompaniesController.prototype, "findPublic", null); +__decorate([ + (0, auth_decorators_1.AuthType)('any'), + (0, common_1.Get)(':id'), + __param(0, (0, common_1.Param)('id')), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String]), + __metadata("design:returntype", void 0) +], CompaniesController.prototype, "findOne", null); +__decorate([ + (0, auth_decorators_1.AuthType)('admin'), + (0, common_1.Post)(), + __param(0, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [company_dto_1.CreateCompanyDto]), + __metadata("design:returntype", void 0) +], CompaniesController.prototype, "create", null); +__decorate([ + (0, auth_decorators_1.AuthType)('admin'), + (0, common_1.Patch)(':id'), + __param(0, (0, common_1.Param)('id')), + __param(1, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String, company_dto_1.UpdateCompanyDto]), + __metadata("design:returntype", void 0) +], CompaniesController.prototype, "update", null); +__decorate([ + (0, auth_decorators_1.AuthType)('admin'), + (0, common_1.Patch)(':id/active'), + __param(0, (0, common_1.Param)('id')), + __param(1, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String, company_dto_1.SetActiveDto]), + __metadata("design:returntype", void 0) +], CompaniesController.prototype, "setActive", null); +__decorate([ + (0, auth_decorators_1.AuthType)('any'), + (0, common_1.Get)(':companyId/bank-accounts'), + __param(0, (0, common_1.Param)('companyId')), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String]), + __metadata("design:returntype", void 0) +], CompaniesController.prototype, "listBankAccounts", null); +__decorate([ + (0, auth_decorators_1.AuthType)('admin'), + (0, common_1.Post)(':companyId/bank-accounts'), + __param(0, (0, common_1.Param)('companyId')), + __param(1, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String, company_dto_1.CreateBankAccountDto]), + __metadata("design:returntype", void 0) +], CompaniesController.prototype, "createBankAccount", null); +exports.CompaniesController = CompaniesController = __decorate([ + (0, common_1.Controller)('companies'), + __metadata("design:paramtypes", [companies_service_1.CompaniesService]) +], CompaniesController); +let BankAccountsController = class BankAccountsController { + companiesService; + constructor(companiesService) { + this.companiesService = companiesService; + } + update(id, dto) { + return this.companiesService.updateBankAccount(id, dto); + } + setActive(id, dto) { + return this.companiesService.setBankAccountActive(id, dto.isActive); + } +}; +exports.BankAccountsController = BankAccountsController; +__decorate([ + (0, auth_decorators_1.AuthType)('admin'), + (0, common_1.Patch)(':id'), + __param(0, (0, common_1.Param)('id')), + __param(1, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String, company_dto_1.UpdateBankAccountDto]), + __metadata("design:returntype", void 0) +], BankAccountsController.prototype, "update", null); +__decorate([ + (0, auth_decorators_1.AuthType)('admin'), + (0, common_1.Patch)(':id/active'), + __param(0, (0, common_1.Param)('id')), + __param(1, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String, company_dto_1.SetActiveDto]), + __metadata("design:returntype", void 0) +], BankAccountsController.prototype, "setActive", null); +exports.BankAccountsController = BankAccountsController = __decorate([ + (0, common_1.Controller)('bank-accounts'), + __metadata("design:paramtypes", [companies_service_1.CompaniesService]) +], BankAccountsController); +//# sourceMappingURL=companies.controller.js.map \ No newline at end of file diff --git a/dist/companies/companies.controller.js.map b/dist/companies/companies.controller.js.map new file mode 100644 index 0000000..8344f08 --- /dev/null +++ b/dist/companies/companies.controller.js.map @@ -0,0 +1 @@ +{"version":3,"file":"companies.controller.js","sourceRoot":"","sources":["../../src/companies/companies.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAQwB;AACxB,2DAAuD;AACvD,0EAAwE;AACxE,mDAM2B;AAGpB,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IACD;IAA7B,YAA6B,gBAAkC;QAAlC,qBAAgB,GAAhB,gBAAgB,CAAkB;IAAG,CAAC;IAInE,OAAO,CAAsB,UAAmB;QAC9C,OAAO,I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CAAC,CAAC;IAC1D,CAAC;IAID,SAAS,CAAc,EAAU,EAAU,GAAiB;QAC1D,OAAO,IAAI,CAAC,gBAAgB,CAAC,oBAAoB,CAAC,EAAE,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC;IACtE,CAAC;CACF,CAAA;AAdY,wDAAsB;AAKjC;IAFC,IAAA,0BAAQ,EAAC,OAAO,CAAC;IACjB,IAAA,cAAK,EAAC,KAAK,CAAC;IACL,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;IAAc,WAAA,IAAA,aAAI,GAAE,CAAA;;6CAAM,kCAAoB;;oDAEhE;AAID;IAFC,IAAA,0BAAQ,EAAC,OAAO,CAAC;IACjB,IAAA,cAAK,EAAC,YAAY,CAAC;IACT,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;IAAc,WAAA,IAAA,aAAI,GAAE,CAAA;;6CAAM,0BAAY;;uDAE3D;iCAbU,sBAAsB;IADlC,IAAA,mBAAU,EAAC,eAAe,CAAC;qCAEqB,oCAAgB;GADpD,sBAAsB,CAclC"} \ No newline at end of file diff --git a/dist/companies/companies.module.d.ts b/dist/companies/companies.module.d.ts new file mode 100644 index 0000000..df21c3d --- /dev/null +++ b/dist/companies/companies.module.d.ts @@ -0,0 +1,2 @@ +export declare class CompaniesModule { +} diff --git a/dist/companies/companies.module.js b/dist/companies/companies.module.js new file mode 100644 index 0000000..0285419 --- /dev/null +++ b/dist/companies/companies.module.js @@ -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.CompaniesModule = void 0; +const common_1 = require("@nestjs/common"); +const companies_controller_1 = require("./companies.controller"); +const companies_service_1 = require("./companies.service"); +let CompaniesModule = class CompaniesModule { +}; +exports.CompaniesModule = CompaniesModule; +exports.CompaniesModule = CompaniesModule = __decorate([ + (0, common_1.Module)({ + controllers: [companies_controller_1.CompaniesController, companies_controller_1.BankAccountsController], + providers: [companies_service_1.CompaniesService], + exports: [companies_service_1.CompaniesService], + }) +], CompaniesModule); +//# sourceMappingURL=companies.module.js.map \ No newline at end of file diff --git a/dist/companies/companies.module.js.map b/dist/companies/companies.module.js.map new file mode 100644 index 0000000..1885f7d --- /dev/null +++ b/dist/companies/companies.module.js.map @@ -0,0 +1 @@ +{"version":3,"file":"companies.module.js","sourceRoot":"","sources":["../../src/companies/companies.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,iEAGgC;AAChC,2DAAuD;AAOhD,IAAM,eAAe,GAArB,MAAM,eAAe;CAAG,CAAA;AAAlB,0CAAe;0BAAf,eAAe;IAL3B,IAAA,eAAM,EAAC;QACN,WAAW,EAAE,CAAC,0CAAmB,EAAE,6CAAsB,CAAC;QAC1D,SAAS,EAAE,CAAC,oCAAgB,CAAC;QAC7B,OAAO,EAAE,CAAC,oCAAgB,CAAC;KAC5B,CAAC;GACW,eAAe,CAAG"} \ No newline at end of file diff --git a/dist/companies/companies.service.d.ts b/dist/companies/companies.service.d.ts new file mode 100644 index 0000000..5eb0344 --- /dev/null +++ b/dist/companies/companies.service.d.ts @@ -0,0 +1,170 @@ +import { PrismaService } from '../prisma/prisma.service'; +import { CreateBankAccountDto, CreateCompanyDto, UpdateBankAccountDto, UpdateCompanyDto } from './dto/company.dto'; +export declare class CompaniesService { + private readonly prisma; + constructor(prisma: PrismaService); + findAll(activeOnly?: boolean): Promise<{ + id: string; + name: string; + slug: string; + description: string; + logoUrl: string | null; + logo: string | undefined; + isActive: boolean; + displayOrder: number; + maxMeteragePerInvoice: number; + cashInvoiceValidityHours: number; + cashInvoiceValidUntilHour: number | undefined; + catalogCount: number; + productCount: number; + bankAccountCount: number; + createdAt: string; + updatedAt: string; + }[]>; + findOne(id: string): Promise<{ + bankAccounts: { + id: string; + companyId: string; + bankName: string; + accountHolder: string; + accountNumber: string; + cardNumber: string; + iban: string; + notes: string | undefined; + isActive: boolean; + displayOrder: number; + createdAt: string; + updatedAt: string; + }[]; + id: string; + name: string; + slug: string; + description: string; + logoUrl: string | null; + logo: string | undefined; + isActive: boolean; + displayOrder: number; + maxMeteragePerInvoice: number; + cashInvoiceValidityHours: number; + cashInvoiceValidUntilHour: number | undefined; + catalogCount: number; + productCount: number; + bankAccountCount: number; + createdAt: string; + updatedAt: string; + }>; + create(dto: CreateCompanyDto): Promise<{ + id: string; + name: string; + slug: string; + description: string; + logoUrl: string | null; + logo: string | undefined; + isActive: boolean; + displayOrder: number; + maxMeteragePerInvoice: number; + cashInvoiceValidityHours: number; + cashInvoiceValidUntilHour: number | undefined; + catalogCount: number; + productCount: number; + bankAccountCount: number; + createdAt: string; + updatedAt: string; + }>; + update(id: string, dto: UpdateCompanyDto): Promise<{ + id: string; + name: string; + slug: string; + description: string; + logoUrl: string | null; + logo: string | undefined; + isActive: boolean; + displayOrder: number; + maxMeteragePerInvoice: number; + cashInvoiceValidityHours: number; + cashInvoiceValidUntilHour: number | undefined; + catalogCount: number; + productCount: number; + bankAccountCount: number; + createdAt: string; + updatedAt: string; + }>; + setActive(id: string, isActive: boolean): Promise<{ + id: string; + name: string; + slug: string; + description: string; + logoUrl: string | null; + logo: string | undefined; + isActive: boolean; + displayOrder: number; + maxMeteragePerInvoice: number; + cashInvoiceValidityHours: number; + cashInvoiceValidUntilHour: number | undefined; + catalogCount: number; + productCount: number; + bankAccountCount: number; + createdAt: string; + updatedAt: string; + }>; + listBankAccounts(companyId: string): Promise<{ + id: string; + companyId: string; + bankName: string; + accountHolder: string; + accountNumber: string; + cardNumber: string; + iban: string; + notes: string | undefined; + isActive: boolean; + displayOrder: number; + createdAt: string; + updatedAt: string; + }[]>; + createBankAccount(companyId: string, dto: CreateBankAccountDto): Promise<{ + id: string; + companyId: string; + bankName: string; + accountHolder: string; + accountNumber: string; + cardNumber: string; + iban: string; + notes: string | undefined; + isActive: boolean; + displayOrder: number; + createdAt: string; + updatedAt: string; + }>; + updateBankAccount(id: string, dto: UpdateBankAccountDto): Promise<{ + id: string; + companyId: string; + bankName: string; + accountHolder: string; + accountNumber: string; + cardNumber: string; + iban: string; + notes: string | undefined; + isActive: boolean; + displayOrder: number; + createdAt: string; + updatedAt: string; + }>; + setBankAccountActive(id: string, isActive: boolean): Promise<{ + id: string; + companyId: string; + bankName: string; + accountHolder: string; + accountNumber: string; + cardNumber: string; + iban: string; + notes: string | undefined; + isActive: boolean; + displayOrder: number; + createdAt: string; + updatedAt: string; + }>; + private ensureCompany; + private ensureBankAccount; + private mapCompany; + private mapBankAccount; +} diff --git a/dist/companies/companies.service.js b/dist/companies/companies.service.js new file mode 100644 index 0000000..d583521 --- /dev/null +++ b/dist/companies/companies.service.js @@ -0,0 +1,219 @@ +"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.CompaniesService = void 0; +const common_1 = require("@nestjs/common"); +const client_1 = require("@prisma/client"); +const prisma_service_1 = require("../prisma/prisma.service"); +let CompaniesService = class CompaniesService { + prisma; + constructor(prisma) { + this.prisma = prisma; + } + async findAll(activeOnly = false) { + const companies = await this.prisma.company.findMany({ + where: activeOnly ? { isActive: true } : undefined, + orderBy: [{ displayOrder: 'asc' }, { name: 'asc' }], + include: { + _count: { select: { catalogs: true, products: true, bankAccounts: true } }, + }, + }); + return companies.map((c) => this.mapCompany(c)); + } + async findOne(id) { + const company = await this.prisma.company.findUnique({ + where: { id }, + include: { + bankAccounts: { orderBy: { displayOrder: 'asc' } }, + _count: { select: { catalogs: true, products: true, bankAccounts: true } }, + }, + }); + if (!company) + throw new common_1.NotFoundException('شرکت یافت نشد'); + return { + ...this.mapCompany(company), + bankAccounts: company.bankAccounts.map((b) => this.mapBankAccount(b)), + }; + } + async create(dto) { + try { + const company = await this.prisma.company.create({ + data: { + name: dto.name.trim(), + slug: dto.slug.trim(), + description: dto.description?.trim() || null, + logoUrl: dto.logoUrl?.trim() || null, + displayOrder: dto.displayOrder ?? 0, + maxMeteragePerInvoice: dto.maxMeteragePerInvoice ?? 5000, + cashInvoiceValidityHours: dto.cashInvoiceValidityHours ?? 8, + cashInvoiceValidUntilHour: dto.cashInvoiceValidUntilHour ?? null, + isActive: dto.isActive ?? true, + }, + include: { + _count: { select: { catalogs: true, products: true, bankAccounts: true } }, + }, + }); + return this.mapCompany(company); + } + catch (e) { + if (e instanceof client_1.Prisma.PrismaClientKnownRequestError && e.code === 'P2002') { + throw new common_1.ConflictException('اسلاگ شرکت تکراری است'); + } + throw e; + } + } + async update(id, dto) { + await this.ensureCompany(id); + try { + const company = await this.prisma.company.update({ + where: { id }, + data: { + name: dto.name?.trim(), + slug: dto.slug?.trim(), + description: dto.description === undefined + ? undefined + : dto.description?.trim() || null, + logoUrl: dto.logoUrl === undefined ? undefined : dto.logoUrl?.trim() || null, + displayOrder: dto.displayOrder, + maxMeteragePerInvoice: dto.maxMeteragePerInvoice, + cashInvoiceValidityHours: dto.cashInvoiceValidityHours, + cashInvoiceValidUntilHour: dto.cashInvoiceValidUntilHour, + isActive: dto.isActive, + }, + include: { + _count: { select: { catalogs: true, products: true, bankAccounts: true } }, + }, + }); + return this.mapCompany(company); + } + catch (e) { + if (e instanceof client_1.Prisma.PrismaClientKnownRequestError && e.code === 'P2002') { + throw new common_1.ConflictException('اسلاگ شرکت تکراری است'); + } + throw e; + } + } + async setActive(id, isActive) { + await this.ensureCompany(id); + const company = await this.prisma.company.update({ + where: { id }, + data: { isActive }, + include: { + _count: { select: { catalogs: true, products: true, bankAccounts: true } }, + }, + }); + return this.mapCompany(company); + } + async listBankAccounts(companyId) { + await this.ensureCompany(companyId); + const accounts = await this.prisma.bankAccount.findMany({ + where: { companyId }, + orderBy: { displayOrder: 'asc' }, + }); + return accounts.map((a) => this.mapBankAccount(a)); + } + async createBankAccount(companyId, dto) { + await this.ensureCompany(companyId); + const account = await this.prisma.bankAccount.create({ + data: { + companyId, + bankName: dto.bankName.trim(), + accountHolder: dto.accountHolder.trim(), + accountNumber: dto.accountNumber.trim(), + cardNumber: dto.cardNumber.trim(), + iban: dto.iban.trim(), + notes: dto.notes?.trim() || null, + displayOrder: dto.displayOrder ?? 0, + isActive: dto.isActive ?? true, + }, + }); + return this.mapBankAccount(account); + } + async updateBankAccount(id, dto) { + await this.ensureBankAccount(id); + const account = await this.prisma.bankAccount.update({ + where: { id }, + data: { + bankName: dto.bankName?.trim(), + accountHolder: dto.accountHolder?.trim(), + accountNumber: dto.accountNumber?.trim(), + cardNumber: dto.cardNumber?.trim(), + iban: dto.iban?.trim(), + notes: dto.notes === undefined ? undefined : dto.notes?.trim() || null, + displayOrder: dto.displayOrder, + isActive: dto.isActive, + }, + }); + return this.mapBankAccount(account); + } + async setBankAccountActive(id, isActive) { + await this.ensureBankAccount(id); + const account = await this.prisma.bankAccount.update({ + where: { id }, + data: { isActive }, + }); + return this.mapBankAccount(account); + } + async ensureCompany(id) { + const company = await this.prisma.company.findUnique({ where: { id } }); + if (!company) + throw new common_1.NotFoundException('شرکت یافت نشد'); + return company; + } + async ensureBankAccount(id) { + const account = await this.prisma.bankAccount.findUnique({ where: { id } }); + if (!account) + throw new common_1.NotFoundException('حساب بانکی یافت نشد'); + return account; + } + mapCompany(company) { + return { + id: company.id, + name: company.name, + slug: company.slug, + description: company.description ?? '', + logoUrl: company.logoUrl, + logo: company.logoUrl ?? undefined, + isActive: company.isActive, + displayOrder: company.displayOrder, + maxMeteragePerInvoice: company.maxMeteragePerInvoice, + cashInvoiceValidityHours: company.cashInvoiceValidityHours, + cashInvoiceValidUntilHour: company.cashInvoiceValidUntilHour ?? undefined, + catalogCount: company._count?.catalogs ?? 0, + productCount: company._count?.products ?? 0, + bankAccountCount: company._count?.bankAccounts ?? 0, + createdAt: company.createdAt.toISOString(), + updatedAt: company.updatedAt.toISOString(), + }; + } + mapBankAccount(account) { + return { + id: account.id, + companyId: account.companyId, + bankName: account.bankName, + accountHolder: account.accountHolder, + accountNumber: account.accountNumber, + cardNumber: account.cardNumber, + iban: account.iban, + notes: account.notes ?? undefined, + isActive: account.isActive, + displayOrder: account.displayOrder, + createdAt: account.createdAt.toISOString(), + updatedAt: account.updatedAt.toISOString(), + }; + } +}; +exports.CompaniesService = CompaniesService; +exports.CompaniesService = CompaniesService = __decorate([ + (0, common_1.Injectable)(), + __metadata("design:paramtypes", [prisma_service_1.PrismaService]) +], CompaniesService); +//# sourceMappingURL=companies.service.js.map \ No newline at end of file diff --git a/dist/companies/companies.service.js.map b/dist/companies/companies.service.js.map new file mode 100644 index 0000000..50910c6 --- /dev/null +++ b/dist/companies/companies.service.js.map @@ -0,0 +1 @@ +{"version":3,"file":"companies.service.js","sourceRoot":"","sources":["../../src/companies/companies.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAIwB;AACxB,2CAAwC;AACxC,6DAAyD;AASlD,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IACE;IAA7B,YAA6B,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;IAEtD,KAAK,CAAC,OAAO,CAAC,UAAU,GA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--- /dev/null +++ b/dist/companies/dto/company.dto.d.ts @@ -0,0 +1,45 @@ +export declare class CreateCompanyDto { + name: string; + slug: string; + description?: string; + logoUrl?: string; + displayOrder?: number; + maxMeteragePerInvoice?: number; + cashInvoiceValidityHours?: number; + cashInvoiceValidUntilHour?: number | null; + isActive?: boolean; +} +export declare class UpdateCompanyDto { + name?: string; + slug?: string; + description?: string | null; + logoUrl?: string | null; + displayOrder?: number; + maxMeteragePerInvoice?: number; + cashInvoiceValidityHours?: number; + cashInvoiceValidUntilHour?: number | null; + isActive?: boolean; +} +export declare class SetActiveDto { + isActive: boolean; +} +export declare class CreateBankAccountDto { + bankName: string; + accountHolder: string; + accountNumber: string; + cardNumber: string; + iban: string; + notes?: string; + displayOrder?: number; + isActive?: boolean; +} +export declare class UpdateBankAccountDto { + bankName?: string; + accountHolder?: string; + accountNumber?: string; + cardNumber?: string; + iban?: string; + notes?: string | null; + displayOrder?: number; + isActive?: boolean; +} diff --git a/dist/companies/dto/company.dto.js b/dist/companies/dto/company.dto.js new file mode 100644 index 0000000..8d259ab --- /dev/null +++ b/dist/companies/dto/company.dto.js @@ -0,0 +1,257 @@ +"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.UpdateBankAccountDto = exports.CreateBankAccountDto = exports.SetActiveDto = exports.UpdateCompanyDto = exports.CreateCompanyDto = void 0; +const class_validator_1 = require("class-validator"); +const class_transformer_1 = require("class-transformer"); +class CreateCompanyDto { + name; + slug; + description; + logoUrl; + displayOrder; + maxMeteragePerInvoice; + cashInvoiceValidityHours; + cashInvoiceValidUntilHour; + isActive; +} +exports.CreateCompanyDto = CreateCompanyDto; +__decorate([ + (0, class_validator_1.IsString)(), + (0, class_validator_1.MinLength)(1), + __metadata("design:type", String) +], CreateCompanyDto.prototype, "name", void 0); +__decorate([ + (0, class_validator_1.IsString)(), + (0, class_validator_1.MinLength)(1), + __metadata("design:type", String) +], CreateCompanyDto.prototype, "slug", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], CreateCompanyDto.prototype, "description", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], CreateCompanyDto.prototype, "logoUrl", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsInt)(), + __metadata("design:type", Number) +], CreateCompanyDto.prototype, "displayOrder", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsInt)(), + (0, class_validator_1.Min)(1), + __metadata("design:type", Number) +], CreateCompanyDto.prototype, "maxMeteragePerInvoice", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsInt)(), + (0, class_validator_1.Min)(1), + __metadata("design:type", Number) +], CreateCompanyDto.prototype, "cashInvoiceValidityHours", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsInt)(), + (0, class_validator_1.Min)(0), + __metadata("design:type", Object) +], CreateCompanyDto.prototype, "cashInvoiceValidUntilHour", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsBoolean)(), + __metadata("design:type", Boolean) +], CreateCompanyDto.prototype, "isActive", void 0); +class UpdateCompanyDto { + name; + slug; + description; + logoUrl; + displayOrder; + maxMeteragePerInvoice; + cashInvoiceValidityHours; + cashInvoiceValidUntilHour; + isActive; +} +exports.UpdateCompanyDto = UpdateCompanyDto; +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + (0, class_validator_1.MinLength)(1), + __metadata("design:type", String) +], UpdateCompanyDto.prototype, "name", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + (0, class_validator_1.MinLength)(1), + __metadata("design:type", String) +], UpdateCompanyDto.prototype, "slug", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", Object) +], UpdateCompanyDto.prototype, "description", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", Object) +], UpdateCompanyDto.prototype, "logoUrl", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsInt)(), + __metadata("design:type", Number) +], UpdateCompanyDto.prototype, "displayOrder", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsInt)(), + (0, class_validator_1.Min)(1), + __metadata("design:type", Number) +], UpdateCompanyDto.prototype, "maxMeteragePerInvoice", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsInt)(), + (0, class_validator_1.Min)(1), + __metadata("design:type", Number) +], UpdateCompanyDto.prototype, "cashInvoiceValidityHours", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsInt)(), + (0, class_validator_1.Min)(0), + __metadata("design:type", Object) +], UpdateCompanyDto.prototype, "cashInvoiceValidUntilHour", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsBoolean)(), + __metadata("design:type", Boolean) +], UpdateCompanyDto.prototype, "isActive", void 0); +class SetActiveDto { + isActive; +} +exports.SetActiveDto = SetActiveDto; +__decorate([ + (0, class_validator_1.IsBoolean)(), + __metadata("design:type", Boolean) +], SetActiveDto.prototype, "isActive", void 0); +class CreateBankAccountDto { + bankName; + accountHolder; + accountNumber; + cardNumber; + iban; + notes; + displayOrder; + isActive; +} +exports.CreateBankAccountDto = CreateBankAccountDto; +__decorate([ + (0, class_validator_1.IsString)(), + (0, class_validator_1.MinLength)(1), + __metadata("design:type", String) +], CreateBankAccountDto.prototype, "bankName", void 0); +__decorate([ + (0, class_validator_1.IsString)(), + (0, class_validator_1.MinLength)(1), + __metadata("design:type", String) +], CreateBankAccountDto.prototype, "accountHolder", void 0); +__decorate([ + (0, class_validator_1.IsString)(), + (0, class_validator_1.MinLength)(1), + __metadata("design:type", String) +], CreateBankAccountDto.prototype, "accountNumber", void 0); +__decorate([ + (0, class_validator_1.IsString)(), + (0, class_validator_1.MinLength)(1), + __metadata("design:type", String) +], CreateBankAccountDto.prototype, "cardNumber", void 0); +__decorate([ + (0, class_validator_1.IsString)(), + (0, class_validator_1.MinLength)(1), + __metadata("design:type", String) +], CreateBankAccountDto.prototype, "iban", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], CreateBankAccountDto.prototype, "notes", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsInt)(), + __metadata("design:type", Number) +], CreateBankAccountDto.prototype, "displayOrder", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsBoolean)(), + __metadata("design:type", Boolean) +], CreateBankAccountDto.prototype, "isActive", void 0); +class UpdateBankAccountDto { + bankName; + accountHolder; + accountNumber; + cardNumber; + iban; + notes; + displayOrder; + isActive; +} +exports.UpdateBankAccountDto = UpdateBankAccountDto; +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], UpdateBankAccountDto.prototype, "bankName", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], UpdateBankAccountDto.prototype, "accountHolder", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], UpdateBankAccountDto.prototype, "accountNumber", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], UpdateBankAccountDto.prototype, "cardNumber", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], UpdateBankAccountDto.prototype, "iban", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", Object) +], UpdateBankAccountDto.prototype, "notes", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsInt)(), + __metadata("design:type", Number) +], UpdateBankAccountDto.prototype, "displayOrder", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsBoolean)(), + __metadata("design:type", Boolean) +], UpdateBankAccountDto.prototype, "isActive", void 0); +//# sourceMappingURL=company.dto.js.map \ No newline at end of file diff --git a/dist/companies/dto/company.dto.js.map b/dist/companies/dto/company.dto.js.map new file mode 100644 index 0000000..7897d52 --- /dev/null +++ b/dist/companies/dto/company.dto.js.map @@ -0,0 +1 @@ +{"version":3,"file":"company.dto.js","sourceRoot":"","sources":["../../../src/companies/dto/company.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAOyB;AACzB,yDAAyC;AAEzC,MAAa,gBAAgB;IAG3B,IAAI,CAAU;IAId,IAAI,CAAU;IAId,WAAW,CAAU;IAIrB,OAAO,CAAU;IAKjB,YAAY,CAAU;IAMtB,qBAAqB,CAAU;I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AId;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;mDACW;AAKtB;IAHC,IAAA,4BAAU,GAAE;IACZ,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC;IAClB,IAAA,uBAAK,GAAE;;0DACc;AAItB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,2BAAS,GAAE;;sDACO"} \ No newline at end of file diff --git a/dist/customers/customers.controller.d.ts b/dist/customers/customers.controller.d.ts new file mode 100644 index 0000000..eda0b8b --- /dev/null +++ b/dist/customers/customers.controller.d.ts @@ -0,0 +1,91 @@ +import { CustomersService } from './customers.service'; +import { CreateCustomerDto, SetCustomerActiveDto, UpdateCustomerDto } from './dto/customer.dto'; +export declare class CustomersController { + private readonly customersService; + constructor(customersService: CustomersService); + findAll(q?: string): Promise<{ + id: string; + firstName: string; + lastName: string; + name: string; + phone: string; + nationalId: string; + customerType: import("@prisma/client").$Enums.CustomerType; + companyId: string | null; + companyName: string; + orderCount: number; + totalMeterage: number; + isActive: boolean; + registeredAt: string; + createdAt: string; + updatedAt: string; + }[]>; + findOne(id: string): Promise<{ + id: string; + firstName: string; + lastName: string; + name: string; + phone: string; + nationalId: string; + customerType: import("@prisma/client").$Enums.CustomerType; + companyId: string | null; + companyName: string; + orderCount: number; + totalMeterage: number; + isActive: boolean; + registeredAt: string; + createdAt: string; + updatedAt: string; + }>; + create(dto: CreateCustomerDto): Promise<{ + id: string; + firstName: string; + lastName: string; + name: string; + phone: string; + nationalId: string; + customerType: import("@prisma/client").$Enums.CustomerType; + companyId: string | null; + companyName: string; + orderCount: number; + totalMeterage: number; + isActive: boolean; + registeredAt: string; + createdAt: string; + updatedAt: string; + }>; + update(id: string, dto: UpdateCustomerDto): Promise<{ + id: string; + firstName: string; + lastName: string; + name: string; + phone: string; + nationalId: string; + customerType: import("@prisma/client").$Enums.CustomerType; + companyId: string | null; + companyName: string; + orderCount: number; + totalMeterage: number; + isActive: boolean; + registeredAt: string; + createdAt: string; + updatedAt: string; + }>; + setActive(id: string, dto: SetCustomerActiveDto): Promise<{ + id: string; + firstName: string; + lastName: string; + name: string; + phone: string; + nationalId: string; + customerType: import("@prisma/client").$Enums.CustomerType; + companyId: string | null; + companyName: string; + orderCount: number; + totalMeterage: number; + isActive: boolean; + registeredAt: string; + createdAt: string; + updatedAt: string; + }>; +} diff --git a/dist/customers/customers.controller.js b/dist/customers/customers.controller.js new file mode 100644 index 0000000..1485e18 --- /dev/null +++ b/dist/customers/customers.controller.js @@ -0,0 +1,84 @@ +"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.CustomersController = void 0; +const common_1 = require("@nestjs/common"); +const customers_service_1 = require("./customers.service"); +const auth_decorators_1 = require("../common/decorators/auth.decorators"); +const customer_dto_1 = require("./dto/customer.dto"); +let CustomersController = class CustomersController { + customersService; + constructor(customersService) { + this.customersService = customersService; + } + findAll(q) { + return this.customersService.findAll(q); + } + findOne(id) { + return this.customersService.findOne(id); + } + create(dto) { + return this.customersService.create(dto); + } + update(id, dto) { + return this.customersService.update(id, dto); + } + setActive(id, dto) { + return this.customersService.setActive(id, dto.isActive); + } +}; +exports.CustomersController = CustomersController; +__decorate([ + (0, common_1.Get)(), + __param(0, (0, common_1.Query)('q')), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String]), + __metadata("design:returntype", void 0) +], CustomersController.prototype, "findAll", null); +__decorate([ + (0, common_1.Get)(':id'), + __param(0, (0, common_1.Param)('id')), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String]), + __metadata("design:returntype", void 0) +], CustomersController.prototype, "findOne", null); +__decorate([ + (0, common_1.Post)(), + __param(0, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [customer_dto_1.CreateCustomerDto]), + __metadata("design:returntype", void 0) +], CustomersController.prototype, "create", null); +__decorate([ + (0, common_1.Patch)(':id'), + __param(0, (0, common_1.Param)('id')), + __param(1, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String, customer_dto_1.UpdateCustomerDto]), + __metadata("design:returntype", void 0) +], CustomersController.prototype, "update", null); +__decorate([ + (0, common_1.Patch)(':id/active'), + __param(0, (0, common_1.Param)('id')), + __param(1, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String, customer_dto_1.SetCustomerActiveDto]), + __metadata("design:returntype", void 0) +], CustomersController.prototype, "setActive", null); +exports.CustomersController = CustomersController = __decorate([ + (0, common_1.Controller)('admin/customers'), + (0, auth_decorators_1.AuthType)('admin'), + __metadata("design:paramtypes", [customers_service_1.CustomersService]) +], CustomersController); +//# sourceMappingURL=customers.controller.js.map \ No newline at end of file diff --git a/dist/customers/customers.controller.js.map b/dist/customers/customers.controller.js.map new file mode 100644 index 0000000..a48c0f7 --- /dev/null +++ b/dist/customers/customers.controller.js.map @@ -0,0 +1 @@ +{"version":3,"file":"customers.controller.js","sourceRoot":"","sources":["../../src/customers/customers.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAQwB;AACxB,2DAAuD;AACvD,0EAAgE;AAChE,qDAI4B;AAIrB,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IACD;IAA7B,YAA6B,gBAAkC;QAAlC,qBAAgB,GAAhB,gBA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1BU,mBAAmB;IAF/B,IAAA,mBAAU,EAAC,iBAAiB,CAAC;IAC7B,IAAA,0BAAQ,EAAC,OAAO,CAAC;qCAE+B,oCAAgB;GADpD,mBAAmB,CA2B/B"} \ No newline at end of file diff --git a/dist/customers/customers.module.d.ts b/dist/customers/customers.module.d.ts new file mode 100644 index 0000000..c3dee1b --- /dev/null +++ b/dist/customers/customers.module.d.ts @@ -0,0 +1,2 @@ +export declare class CustomersModule { +} diff --git a/dist/customers/customers.module.js b/dist/customers/customers.module.js new file mode 100644 index 0000000..7b5ed3a --- /dev/null +++ b/dist/customers/customers.module.js @@ -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.CustomersModule = void 0; +const common_1 = require("@nestjs/common"); +const customers_controller_1 = require("./customers.controller"); +const customers_service_1 = require("./customers.service"); +let CustomersModule = class CustomersModule { +}; +exports.CustomersModule = CustomersModule; +exports.CustomersModule = CustomersModule = __decorate([ + (0, common_1.Module)({ + controllers: [customers_controller_1.CustomersController], + providers: [customers_service_1.CustomersService], + exports: [customers_service_1.CustomersService], + }) +], CustomersModule); +//# sourceMappingURL=customers.module.js.map \ No newline at end of file diff --git a/dist/customers/customers.module.js.map b/dist/customers/customers.module.js.map new file mode 100644 index 0000000..68e1e69 --- /dev/null +++ b/dist/customers/customers.module.js.map @@ -0,0 +1 @@ +{"version":3,"file":"customers.module.js","sourceRoot":"","sources":["../../src/customers/customers.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,iEAA6D;AAC7D,2DAAuD;AAOhD,IAAM,eAAe,GAArB,MAAM,eAAe;CAAG,CAAA;AAAlB,0CAAe;0BAAf,eAAe;IAL3B,IAAA,eAAM,EAAC;QACN,WAAW,EAAE,CAAC,0CAAmB,CAAC;QAClC,SAAS,EAAE,CAAC,oCAAgB,CAAC;QAC7B,OAAO,EAAE,CAAC,oCAAgB,CAAC;KAC5B,CAAC;GACW,eAAe,CAAG"} \ No newline at end of file diff --git a/dist/customers/customers.service.d.ts b/dist/customers/customers.service.d.ts new file mode 100644 index 0000000..7bb0d54 --- /dev/null +++ b/dist/customers/customers.service.d.ts @@ -0,0 +1,94 @@ +import { PrismaService } from '../prisma/prisma.service'; +import { CreateCustomerDto, UpdateCustomerDto } from './dto/customer.dto'; +export declare class CustomersService { + private readonly prisma; + constructor(prisma: PrismaService); + findAll(q?: string): Promise<{ + id: string; + firstName: string; + lastName: string; + name: string; + phone: string; + nationalId: string; + customerType: import("@prisma/client").$Enums.CustomerType; + companyId: string | null; + companyName: string; + orderCount: number; + totalMeterage: number; + isActive: boolean; + registeredAt: string; + createdAt: string; + updatedAt: string; + }[]>; + findOne(id: string): Promise<{ + id: string; + firstName: string; + lastName: string; + name: string; + phone: string; + nationalId: string; + customerType: import("@prisma/client").$Enums.CustomerType; + companyId: string | null; + companyName: string; + orderCount: number; + totalMeterage: number; + isActive: boolean; + registeredAt: string; + createdAt: string; + updatedAt: string; + }>; + create(dto: CreateCustomerDto): Promise<{ + id: string; + firstName: string; + lastName: string; + name: string; + phone: string; + nationalId: string; + customerType: import("@prisma/client").$Enums.CustomerType; + companyId: string | null; + companyName: string; + orderCount: number; + totalMeterage: number; + isActive: boolean; + registeredAt: string; + createdAt: string; + updatedAt: string; + }>; + update(id: string, dto: UpdateCustomerDto): Promise<{ + id: string; + firstName: string; + lastName: string; + name: string; + phone: string; + nationalId: string; + customerType: import("@prisma/client").$Enums.CustomerType; + companyId: string | null; + companyName: string; + orderCount: number; + totalMeterage: number; + isActive: boolean; + registeredAt: string; + createdAt: string; + updatedAt: string; + }>; + setActive(id: string, isActive: boolean): Promise<{ + id: string; + firstName: string; + lastName: string; + name: string; + phone: string; + nationalId: string; + customerType: import("@prisma/client").$Enums.CustomerType; + companyId: string | null; + companyName: string; + orderCount: number; + totalMeterage: number; + isActive: boolean; + registeredAt: string; + createdAt: string; + updatedAt: string; + }>; + private resolveNames; + private ensure; + private map; +} diff --git a/dist/customers/customers.service.js b/dist/customers/customers.service.js new file mode 100644 index 0000000..f63f884 --- /dev/null +++ b/dist/customers/customers.service.js @@ -0,0 +1,192 @@ +"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.CustomersService = void 0; +const common_1 = require("@nestjs/common"); +const client_1 = require("@prisma/client"); +const prisma_service_1 = require("../prisma/prisma.service"); +const phone_1 = require("../common/utils/phone"); +const name_1 = require("../common/utils/name"); +let CustomersService = class CustomersService { + prisma; + constructor(prisma) { + this.prisma = prisma; + } + async findAll(q) { + const customers = await this.prisma.customer.findMany({ + where: q + ? { + OR: [ + { firstName: { contains: q, mode: 'insensitive' } }, + { lastName: { contains: q, mode: 'insensitive' } }, + { phone: { contains: (0, phone_1.toEnglishDigits)(q) } }, + { nationalId: { contains: (0, phone_1.toEnglishDigits)(q) } }, + ], + } + : undefined, + orderBy: { createdAt: 'desc' }, + include: { + company: { select: { name: true } }, + orders: { select: { totalMeterage: true } }, + }, + }); + return customers.map((c) => this.map(c)); + } + async findOne(id) { + const customer = await this.prisma.customer.findUnique({ + where: { id }, + include: { + company: { select: { name: true } }, + orders: { select: { totalMeterage: true } }, + }, + }); + if (!customer) + throw new common_1.NotFoundException('مشتری یافت نشد'); + return this.map(customer); + } + async create(dto) { + const phone = (0, phone_1.normalizePhone)((0, phone_1.toEnglishDigits)(dto.phone)); + if (!(0, phone_1.isValidPhone)(phone)) { + throw new common_1.BadRequestException('شماره موبایل نامعتبر است'); + } + const { firstName, lastName } = this.resolveNames(dto); + if (dto.companyId) { + const company = await this.prisma.company.findUnique({ + where: { id: dto.companyId }, + }); + if (!company) + throw new common_1.NotFoundException('شرکت یافت نشد'); + } + try { + const customer = await this.prisma.customer.create({ + data: { + firstName, + lastName, + phone, + nationalId: dto.nationalId?.trim() || null, + customerType: dto.customerType ?? client_1.CustomerType.wholesale, + companyId: dto.companyId || null, + isActive: dto.isActive ?? true, + }, + include: { + company: { select: { name: true } }, + orders: { select: { totalMeterage: true } }, + }, + }); + return this.map(customer); + } + catch (e) { + if (e instanceof client_1.Prisma.PrismaClientKnownRequestError && e.code === 'P2002') { + throw new common_1.ConflictException('این شماره قبلاً ثبت شده است'); + } + throw e; + } + } + async update(id, dto) { + await this.ensure(id); + const phone = dto.phone !== undefined + ? (0, phone_1.normalizePhone)((0, phone_1.toEnglishDigits)(dto.phone)) + : undefined; + if (phone !== undefined && !(0, phone_1.isValidPhone)(phone)) { + throw new common_1.BadRequestException('شماره موبایل نامعتبر است'); + } + let firstName; + let lastName; + if (dto.name !== undefined || dto.firstName !== undefined || dto.lastName !== undefined) { + const names = this.resolveNames(dto); + firstName = names.firstName; + lastName = names.lastName; + } + try { + const customer = await this.prisma.customer.update({ + where: { id }, + data: { + firstName, + lastName, + phone, + nationalId: dto.nationalId === undefined + ? undefined + : dto.nationalId?.trim() || null, + customerType: dto.customerType, + companyId: dto.companyId === undefined ? undefined : dto.companyId || null, + isActive: dto.isActive, + }, + include: { + company: { select: { name: true } }, + orders: { select: { totalMeterage: true } }, + }, + }); + return this.map(customer); + } + catch (e) { + if (e instanceof client_1.Prisma.PrismaClientKnownRequestError && e.code === 'P2002') { + throw new common_1.ConflictException('این شماره قبلاً ثبت شده است'); + } + throw e; + } + } + async setActive(id, isActive) { + await this.ensure(id); + const customer = await this.prisma.customer.update({ + where: { id }, + data: { isActive }, + include: { + company: { select: { name: true } }, + orders: { select: { totalMeterage: true } }, + }, + }); + return this.map(customer); + } + resolveNames(dto) { + if (dto.name?.trim()) { + return (0, name_1.splitFullName)(dto.name); + } + const firstName = dto.firstName?.trim(); + const lastName = dto.lastName?.trim() ?? ''; + if (!firstName) { + throw new common_1.BadRequestException('نام مشتری الزامی است'); + } + return { firstName, lastName }; + } + async ensure(id) { + const customer = await this.prisma.customer.findUnique({ where: { id } }); + if (!customer) + throw new common_1.NotFoundException('مشتری یافت نشد'); + return customer; + } + map(customer) { + const totalMeterage = customer.orders.reduce((sum, o) => sum + o.totalMeterage, 0); + const name = (0, name_1.joinFullName)(customer.firstName, customer.lastName); + return { + id: customer.id, + firstName: customer.firstName, + lastName: customer.lastName, + name, + phone: customer.phone, + nationalId: customer.nationalId ?? '', + customerType: customer.customerType, + companyId: customer.companyId, + companyName: customer.company?.name ?? '', + orderCount: customer.orders.length, + totalMeterage, + isActive: customer.isActive, + registeredAt: customer.createdAt.toISOString(), + createdAt: customer.createdAt.toISOString(), + updatedAt: customer.updatedAt.toISOString(), + }; + } +}; +exports.CustomersService = CustomersService; +exports.CustomersService = CustomersService = __decorate([ + (0, common_1.Injectable)(), + __metadata("design:paramtypes", [prisma_service_1.PrismaService]) +], CustomersService); +//# sourceMappingURL=customers.service.js.map \ No newline at end of file diff --git a/dist/customers/customers.service.js.map b/dist/customers/customers.service.js.map new file mode 100644 index 0000000..957cabc --- /dev/null +++ b/dist/customers/customers.service.js.map @@ -0,0 +1 @@ +{"version":3,"file":"customers.service.js","sourceRoot":"","sources":["../../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customer.dto.d.ts @@ -0,0 +1,24 @@ +import { CustomerType } from '@prisma/client'; +export declare class CreateCustomerDto { + firstName?: string; + lastName?: string; + name?: string; + phone: string; + nationalId?: string; + customerType?: CustomerType; + companyId?: string | null; + isActive?: boolean; +} +export declare class UpdateCustomerDto { + firstName?: string; + lastName?: string; + name?: string; + phone?: string; + nationalId?: string | null; + customerType?: CustomerType; + companyId?: string | null; + isActive?: boolean; +} +export declare class SetCustomerActiveDto { + isActive: boolean; +} diff --git a/dist/customers/dto/customer.dto.js b/dist/customers/dto/customer.dto.js new file mode 100644 index 0000000..4ff4295 --- /dev/null +++ b/dist/customers/dto/customer.dto.js @@ -0,0 +1,125 @@ +"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.SetCustomerActiveDto = exports.UpdateCustomerDto = exports.CreateCustomerDto = void 0; +const class_validator_1 = require("class-validator"); +const client_1 = require("@prisma/client"); +class CreateCustomerDto { + firstName; + lastName; + name; + phone; + nationalId; + customerType; + companyId; + isActive; +} +exports.CreateCustomerDto = CreateCustomerDto; +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], CreateCustomerDto.prototype, "firstName", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], CreateCustomerDto.prototype, "lastName", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], CreateCustomerDto.prototype, "name", void 0); +__decorate([ + (0, class_validator_1.IsString)(), + (0, class_validator_1.MinLength)(10), + __metadata("design:type", String) +], CreateCustomerDto.prototype, "phone", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], CreateCustomerDto.prototype, "nationalId", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsEnum)(client_1.CustomerType), + __metadata("design:type", String) +], CreateCustomerDto.prototype, "customerType", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", Object) +], CreateCustomerDto.prototype, "companyId", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsBoolean)(), + __metadata("design:type", Boolean) +], CreateCustomerDto.prototype, "isActive", void 0); +class UpdateCustomerDto { + firstName; + lastName; + name; + phone; + nationalId; + customerType; + companyId; + isActive; +} +exports.UpdateCustomerDto = UpdateCustomerDto; +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], UpdateCustomerDto.prototype, "firstName", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], UpdateCustomerDto.prototype, "lastName", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], UpdateCustomerDto.prototype, "name", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], UpdateCustomerDto.prototype, "phone", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", Object) +], UpdateCustomerDto.prototype, "nationalId", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsEnum)(client_1.CustomerType), + __metadata("design:type", String) +], UpdateCustomerDto.prototype, "customerType", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", Object) +], UpdateCustomerDto.prototype, "companyId", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsBoolean)(), + __metadata("design:type", Boolean) +], UpdateCustomerDto.prototype, "isActive", void 0); +class SetCustomerActiveDto { + isActive; +} +exports.SetCustomerActiveDto = SetCustomerActiveDto; +__decorate([ + (0, class_validator_1.IsBoolean)(), + __metadata("design:type", Boolean) +], SetCustomerActiveDto.prototype, "isActive", void 0); +//# sourceMappingURL=customer.dto.js.map \ No newline at end of file diff --git a/dist/customers/dto/customer.dto.js.map b/dist/customers/dto/customer.dto.js.map new file mode 100644 index 0000000..922c9ef --- /dev/null +++ b/dist/customers/dto/customer.dto.js.map @@ -0,0 +1 @@ +{"version":3,"file":"customer.dto.js","sourceRoot":"","sources":["../../../src/customers/dto/customer.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAMyB;AACzB,2CAA8C;AAE9C,MAAa,iBAAiB;IAG5B,SAAS,CAAU;IAInB,QAAQ,CAAU;IAKlB,IAAI,CAAU;IAId,KAAK,CAAU;IAIf,UAAU,CAAU;IAIpB,YAAY,CAAgB;IAI5B,SAAS,CAAiB;IAI1B,QAAQ,CAAW;CACpB;AAjCD,8CAiCC;AA9BC;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;oDACQ;AAInB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;mDACO;AAKlB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;+CACG;AAId;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,2BAAS,EAAC,EAAE,CAAC;;gDACC;AAIf;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;qDACS;AAIpB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,wBAAM,EAAC,qBAAY,CAAC;;uDACO;AAI5B;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;oDACe;AAI1B;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,2BAAS,GAAE;;mDACO;AAGrB,MAAa,iBAAiB;IAG5B,SAAS,CAAU;IAInB,QAAQ,CAAU;IAIlB,IAAI,CAAU;IAId,KAAK,CAAU;IAIf,UAAU,CAAiB;IAI3B,YAAY,CAAgB;IAI5B,SAAS,CAAiB;IAI1B,QAAQ,CAAW;CACpB;AAhCD,8CAgCC;AA7BC;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;oDACQ;AAInB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;mDACO;AAIlB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;+CACG;AAId;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;gDACI;AAIf;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;qDACgB;AAI3B;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,wBAAM,EAAC,qBAAY,CAAC;;uDACO;AAI5B;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;oDACe;AAI1B;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,2BAAS,GAAE;;mDACO;AAGrB,MAAa,oBAAoB;IAE/B,QAAQ,CAAW;CACpB;AAHD,oDAGC;AADC;IADC,IAAA,2BAAS,GAAE;;sDACO"} \ No newline at end of file diff --git a/dist/dashboard/dashboard.controller.d.ts b/dist/dashboard/dashboard.controller.d.ts new file mode 100644 index 0000000..ab026ea --- /dev/null +++ b/dist/dashboard/dashboard.controller.d.ts @@ -0,0 +1,155 @@ +import { DashboardService } from './dashboard.service'; +export declare class DashboardController { + private readonly dashboardService; + constructor(dashboardService: DashboardService); + getDashboard(): Promise<{ + stats: { + newOrders: number; + pendingReview: number; + pendingCheck: number; + finalApproval: number; + todaySales: number; + todaySalesGrowth: number; + monthSales: number; + }; + recentOrders: { + id: string; + orderNumber: string; + userId: string; + companyId: string; + companyName: string; + settlementType: import("@prisma/client").$Enums.SettlementType; + settlementMethod: import("@prisma/client").$Enums.SettlementType; + checkMode: import("@prisma/client").$Enums.CheckRegistrationMode | undefined; + status: import("@prisma/client").$Enums.OrderStatus; + adminStatus: string; + totalMeterage: number; + meterage: number; + totalAmount: number | null; + shippingCost: number | null; + totalDiscount: number | null; + finalAmount: number | null; + notes: string | undefined; + checkRassDays: number | undefined; + checkRassDate: string | undefined; + cashInvoiceExpiresAt: string | undefined; + createdAt: string; + updatedAt: string; + customerName: string; + customerPhone: string; + customerNationalId: string | undefined; + customerType: import("@prisma/client").$Enums.CustomerType; + items: { + id: string; + productId: string | undefined; + catalogCode: string; + productName: string; + productCode: string | undefined; + color: string; + requestedMeterage: number; + confirmedMeterage: number | null; + unitPrice: number | null; + supplyPrice: number | null; + unitDiscount: number; + discount: number; + lineTotal: number | null; + totalAmount: number | null; + notes: string | undefined; + }[]; + checks: { + id: string; + orderId: string; + row: number; + amount: number; + dueDate: string; + sayadId: string | undefined; + checkNumber: string | undefined; + ownerNationalId: string | undefined; + ownerFirstName: string | undefined; + ownerLastName: string | undefined; + bankName: string; + branchName: string | undefined; + frontImage: string | undefined; + backImage: string | undefined; + notes: string | undefined; + mode: import("@prisma/client").$Enums.CheckRegistrationMode; + status: import("@prisma/client").$Enums.CheckStatus; + createdAt: string; + updatedAt: string; + }[]; + cashReceipt: { + id: string; + amount: number; + paidAmount: number | null; + transferDate: string | null; + transferTime: string | undefined; + trackingNumber: string | undefined; + trackingCode: string | undefined; + destinationAccountId: string | undefined; + receiptImage: string | undefined; + notes: string | undefined; + expiresAt: string | undefined; + status: import("@prisma/client").$Enums.CashPaymentStatus; + submittedAt: string | undefined; + createdAt: string; + } | undefined; + shipment: { + id: string; + orderId: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + } | undefined; + statusHistory: { + id: string; + fromStatus: import("@prisma/client").$Enums.OrderStatus | null; + toStatus: import("@prisma/client").$Enums.OrderStatus; + changedBy: string; + note: string | undefined; + reason: string | undefined; + changedAt: string; + }[]; + }[]; + salesChartData: number[]; + chartAxisLabels: string[]; + checkDeadlines: { + id: string; + label: string; + tone: "warning" | "danger" | "neutral"; + count: number; + amount: number; + }[]; + notifications: { + id: string; + title: string; + body: string; + tone: import("@prisma/client").$Enums.NotificationTone | null; + link: string | null; + isRead: boolean; + sentAt: string; + }[]; + messages: { + id: string; + senderName: string; + subject: string; + preview: string; + isRead: boolean; + sentAt: string; + }[]; + }>; + getReports(): Promise<{ + reportSalesByCompany: { + companyName: string; + orderCount: number; + totalAmount: number; + meterage: number; + }[]; + reportOrdersByStatus: { + status: string; + count: number; + }[]; + }>; +} diff --git a/dist/dashboard/dashboard.controller.js b/dist/dashboard/dashboard.controller.js new file mode 100644 index 0000000..5714a0c --- /dev/null +++ b/dist/dashboard/dashboard.controller.js @@ -0,0 +1,46 @@ +"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.DashboardController = void 0; +const common_1 = require("@nestjs/common"); +const dashboard_service_1 = require("./dashboard.service"); +const auth_decorators_1 = require("../common/decorators/auth.decorators"); +let DashboardController = class DashboardController { + dashboardService; + constructor(dashboardService) { + this.dashboardService = dashboardService; + } + getDashboard() { + return this.dashboardService.getDashboard(); + } + getReports() { + return this.dashboardService.getReports(); + } +}; +exports.DashboardController = DashboardController; +__decorate([ + (0, common_1.Get)('dashboard'), + __metadata("design:type", Function), + __metadata("design:paramtypes", []), + __metadata("design:returntype", void 0) +], DashboardController.prototype, "getDashboard", null); +__decorate([ + (0, common_1.Get)('reports'), + __metadata("design:type", Function), + __metadata("design:paramtypes", []), + __metadata("design:returntype", void 0) +], DashboardController.prototype, "getReports", null); +exports.DashboardController = DashboardController = __decorate([ + (0, common_1.Controller)('admin'), + (0, auth_decorators_1.AuthType)('admin'), + __metadata("design:paramtypes", [dashboard_service_1.DashboardService]) +], DashboardController); +//# sourceMappingURL=dashboard.controller.js.map \ No newline at end of file diff --git a/dist/dashboard/dashboard.controller.js.map b/dist/dashboard/dashboard.controller.js.map new file mode 100644 index 0000000..63f26ab --- /dev/null +++ b/dist/dashboard/dashboard.controller.js.map @@ -0,0 +1 @@ +{"version":3,"file":"dashboard.controller.js","sourceRoot":"","sources":["../../src/dashboard/dashboard.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAiD;AACjD,2DAAuD;AACvD,0EAAgE;AAIzD,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IACD;IAA7B,YAA6B,gBAAkC;QAAlC,qBAAgB,GAAhB,gBAAgB,CAAkB;IAAG,CAAC;IAGnE,YAAY;QACV,OAAO,IAAI,CAAC,gBAAgB,CAAC,YAAY,EAAE,CAAC;IAC9C,CAAC;IAGD,UAAU;QACR,OAAO,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,CAAC;IAC5C,CAAC;CACF,CAAA;AAZY,kDAAmB;AAI9B;IADC,IAAA,YAAG,EAAC,WAAW,CAAC;;;;uDAGhB;AAGD;IADC,IAAA,YAAG,EAAC,SAAS,CAAC;;;;qDAGd;8BAXU,mBAAmB;IAF/B,IAAA,mBAAU,EAAC,OAAO,CAAC;IACnB,IAAA,0BAAQ,EAAC,OAAO,CAAC;qCAE+B,oCAAgB;GADpD,mBAAmB,CAY/B"} \ No newline at end of file diff --git a/dist/dashboard/dashboard.module.d.ts b/dist/dashboard/dashboard.module.d.ts new file mode 100644 index 0000000..6054687 --- /dev/null +++ b/dist/dashboard/dashboard.module.d.ts @@ -0,0 +1,2 @@ +export declare class DashboardModule { +} diff --git a/dist/dashboard/dashboard.module.js b/dist/dashboard/dashboard.module.js new file mode 100644 index 0000000..22f8496 --- /dev/null +++ b/dist/dashboard/dashboard.module.js @@ -0,0 +1,24 @@ +"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.DashboardModule = void 0; +const common_1 = require("@nestjs/common"); +const dashboard_controller_1 = require("./dashboard.controller"); +const dashboard_service_1 = require("./dashboard.service"); +const orders_module_1 = require("../orders/orders.module"); +let DashboardModule = class DashboardModule { +}; +exports.DashboardModule = DashboardModule; +exports.DashboardModule = DashboardModule = __decorate([ + (0, common_1.Module)({ + imports: [orders_module_1.OrdersModule], + controllers: [dashboard_controller_1.DashboardController], + providers: [dashboard_service_1.DashboardService], + }) +], DashboardModule); +//# sourceMappingURL=dashboard.module.js.map \ No newline at end of file diff --git a/dist/dashboard/dashboard.module.js.map b/dist/dashboard/dashboard.module.js.map new file mode 100644 index 0000000..7562ba6 --- /dev/null +++ b/dist/dashboard/dashboard.module.js.map @@ -0,0 +1 @@ +{"version":3,"file":"dashboard.module.js","sourceRoot":"","sources":["../../src/dashboard/dashboard.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,iEAA6D;AAC7D,2DAAuD;AACvD,2DAAuD;AAOhD,IAAM,eAAe,GAArB,MAAM,eAAe;CAAG,CAAA;AAAlB,0CAAe;0BAAf,eAAe;IAL3B,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,4BAAY,CAAC;QACvB,WAAW,EAAE,CAAC,0CAAmB,CAAC;QAClC,SAAS,EAAE,CAAC,oCAAgB,CAAC;KAC9B,CAAC;GACW,eAAe,CAAG"} \ No newline at end of file diff --git a/dist/dashboard/dashboard.service.d.ts b/dist/dashboard/dashboard.service.d.ts new file mode 100644 index 0000000..9c6cfd5 --- /dev/null +++ b/dist/dashboard/dashboard.service.d.ts @@ -0,0 +1,158 @@ +import { PrismaService } from '../prisma/prisma.service'; +import { OrdersService } from '../orders/orders.service'; +export declare class DashboardService { + private readonly prisma; + private readonly ordersService; + constructor(prisma: PrismaService, ordersService: OrdersService); + getDashboard(): Promise<{ + stats: { + newOrders: number; + pendingReview: number; + pendingCheck: number; + finalApproval: number; + todaySales: number; + todaySalesGrowth: number; + monthSales: number; + }; + recentOrders: { + id: string; + orderNumber: string; + userId: string; + companyId: string; + companyName: string; + settlementType: import("@prisma/client").$Enums.SettlementType; + settlementMethod: import("@prisma/client").$Enums.SettlementType; + checkMode: import("@prisma/client").$Enums.CheckRegistrationMode | undefined; + status: import("@prisma/client").$Enums.OrderStatus; + adminStatus: string; + totalMeterage: number; + meterage: number; + totalAmount: number | null; + shippingCost: number | null; + totalDiscount: number | null; + finalAmount: number | null; + notes: string | undefined; + checkRassDays: number | undefined; + checkRassDate: string | undefined; + cashInvoiceExpiresAt: string | undefined; + createdAt: string; + updatedAt: string; + customerName: string; + customerPhone: string; + customerNationalId: string | undefined; + customerType: import("@prisma/client").$Enums.CustomerType; + items: { + id: string; + productId: string | undefined; + catalogCode: string; + productName: string; + productCode: string | undefined; + color: string; + requestedMeterage: number; + confirmedMeterage: number | null; + unitPrice: number | null; + supplyPrice: number | null; + unitDiscount: number; + discount: number; + lineTotal: number | null; + totalAmount: number | null; + notes: string | undefined; + }[]; + checks: { + id: string; + orderId: string; + row: number; + amount: number; + dueDate: string; + sayadId: string | undefined; + checkNumber: string | undefined; + ownerNationalId: string | undefined; + ownerFirstName: string | undefined; + ownerLastName: string | undefined; + bankName: string; + branchName: string | undefined; + frontImage: string | undefined; + backImage: string | undefined; + notes: string | undefined; + mode: import("@prisma/client").$Enums.CheckRegistrationMode; + status: import("@prisma/client").$Enums.CheckStatus; + createdAt: string; + updatedAt: string; + }[]; + cashReceipt: { + id: string; + amount: number; + paidAmount: number | null; + transferDate: string | null; + transferTime: string | undefined; + trackingNumber: string | undefined; + trackingCode: string | undefined; + destinationAccountId: string | undefined; + receiptImage: string | undefined; + notes: string | undefined; + expiresAt: string | undefined; + status: import("@prisma/client").$Enums.CashPaymentStatus; + submittedAt: string | undefined; + createdAt: string; + } | undefined; + shipment: { + id: string; + orderId: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + } | undefined; + statusHistory: { + id: string; + fromStatus: import("@prisma/client").$Enums.OrderStatus | null; + toStatus: import("@prisma/client").$Enums.OrderStatus; + changedBy: string; + note: string | undefined; + reason: string | undefined; + changedAt: string; + }[]; + }[]; + salesChartData: number[]; + chartAxisLabels: string[]; + checkDeadlines: { + id: string; + label: string; + tone: "warning" | "danger" | "neutral"; + count: number; + amount: number; + }[]; + notifications: { + id: string; + title: string; + body: string; + tone: import("@prisma/client").$Enums.NotificationTone | null; + link: string | null; + isRead: boolean; + sentAt: string; + }[]; + messages: { + id: string; + senderName: string; + subject: string; + preview: string; + isRead: boolean; + sentAt: string; + }[]; + }>; + getReports(): Promise<{ + reportSalesByCompany: { + companyName: string; + orderCount: number; + totalAmount: number; + meterage: number; + }[]; + reportOrdersByStatus: { + status: string; + count: number; + }[]; + }>; + private buildCheckDeadlines; +} diff --git a/dist/dashboard/dashboard.service.js b/dist/dashboard/dashboard.service.js new file mode 100644 index 0000000..fe7d159 --- /dev/null +++ b/dist/dashboard/dashboard.service.js @@ -0,0 +1,219 @@ +"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.DashboardService = void 0; +const common_1 = require("@nestjs/common"); +const prisma_service_1 = require("../prisma/prisma.service"); +const order_status_1 = require("../common/utils/order-status"); +const orders_service_1 = require("../orders/orders.service"); +let DashboardService = class DashboardService { + prisma; + ordersService; + constructor(prisma, ordersService) { + this.prisma = prisma; + this.ordersService = ordersService; + } + async getDashboard() { + const now = new Date(); + const startOfToday = new Date(now); + startOfToday.setHours(0, 0, 0, 0); + const startOfYesterday = new Date(startOfToday); + startOfYesterday.setDate(startOfYesterday.getDate() - 1); + const startOfMonth = new Date(now.getFullYear(), now.getMonth(), 1); + const startOfChart = new Date(startOfToday); + startOfChart.setDate(startOfChart.getDate() - 27); + const [newOrders, pendingReview, pendingCheck, finalApproval, todayOrders, yesterdayOrders, monthOrders, chartOrders, recentOrders, checks, notifications, messages,] = await Promise.all([ + this.prisma.order.count({ + where: { createdAt: { gte: startOfToday } }, + }), + this.prisma.order.count({ + where: { status: { in: order_status_1.ADMIN_STATUS_MAP.pending_review } }, + }), + this.prisma.order.count({ + where: { status: { in: order_status_1.ADMIN_STATUS_MAP.pending_check } }, + }), + this.prisma.order.count({ + where: { status: { in: order_status_1.ADMIN_STATUS_MAP.final_approval } }, + }), + this.prisma.order.findMany({ + where: { createdAt: { gte: startOfToday } }, + select: { finalAmount: true, totalAmount: true }, + }), + this.prisma.order.findMany({ + where: { + createdAt: { gte: startOfYesterday, lt: startOfToday }, + }, + select: { finalAmount: true, totalAmount: true }, + }), + this.prisma.order.findMany({ + where: { createdAt: { gte: startOfMonth } }, + select: { finalAmount: true, totalAmount: true }, + }), + this.prisma.order.findMany({ + where: { createdAt: { gte: startOfChart } }, + select: { + createdAt: true, + finalAmount: true, + totalAmount: true, + }, + }), + this.prisma.order.findMany({ + orderBy: { createdAt: 'desc' }, + take: 5, + include: { + items: true, + checks: { orderBy: { row: 'asc' } }, + cashReceipt: true, + statusHistory: { orderBy: { changedAt: 'asc' } }, + shipment: true, + user: true, + company: true, + }, + }), + this.prisma.check.findMany({ + where: { + status: { not: 'rejected' }, + dueDate: { + gte: startOfToday, + lte: new Date(startOfToday.getTime() + 30 * 24 * 60 * 60 * 1000), + }, + }, + select: { dueDate: true, amount: true }, + }), + this.prisma.adminNotification.findMany({ + orderBy: { sentAt: 'desc' }, + take: 20, + }), + this.prisma.internalMessage.findMany({ + orderBy: { sentAt: 'desc' }, + take: 20, + }), + ]); + const sumAmounts = (rows) => rows.reduce((s, o) => s + (o.finalAmount ?? o.totalAmount ?? 0), 0); + const todaySales = sumAmounts(todayOrders); + const yesterdaySales = sumAmounts(yesterdayOrders); + const monthSales = sumAmounts(monthOrders); + const todaySalesGrowth = yesterdaySales > 0 + ? Math.round(((todaySales - yesterdaySales) / yesterdaySales) * 100) + : todaySales > 0 + ? 100 + : 0; + const salesByDay = Array.from({ length: 28 }, () => 0); + for (const order of chartOrders) { + const dayIndex = Math.floor((order.createdAt.getTime() - startOfChart.getTime()) / + (24 * 60 * 60 * 1000)); + if (dayIndex >= 0 && dayIndex < 28) { + salesByDay[dayIndex] += order.finalAmount ?? order.totalAmount ?? 0; + } + } + const maxSale = Math.max(...salesByDay, 1); + const salesChartData = salesByDay.map((v) => Number((v / maxSale).toFixed(3))); + const checkDeadlines = this.buildCheckDeadlines(checks, startOfToday); + return { + stats: { + newOrders, + pendingReview, + pendingCheck, + finalApproval, + todaySales, + todaySalesGrowth, + monthSales, + }, + recentOrders: recentOrders.map((o) => this.ordersService.mapOrder(o, true)), + salesChartData, + chartAxisLabels: ['۱', '۷', '۱۴', '۲۱', '۲۸'], + checkDeadlines, + notifications: notifications.map((n) => ({ + id: n.id, + title: n.title, + body: n.body, + tone: n.tone, + link: n.link, + isRead: n.isRead, + sentAt: n.sentAt.toISOString(), + })), + messages: messages.map((m) => ({ + id: m.id, + senderName: m.senderName, + subject: m.subject, + preview: m.preview, + isRead: m.isRead, + sentAt: m.sentAt.toISOString(), + })), + }; + } + async getReports() { + const orders = await this.prisma.order.findMany({ + select: { + companyName: true, + status: true, + totalMeterage: true, + finalAmount: true, + totalAmount: true, + }, + }); + const byCompany = new Map(); + const byStatus = new Map(); + for (const order of orders) { + const company = byCompany.get(order.companyName) ?? { + companyName: order.companyName, + orderCount: 0, + totalAmount: 0, + meterage: 0, + }; + company.orderCount += 1; + company.totalAmount += order.finalAmount ?? order.totalAmount ?? 0; + company.meterage += order.totalMeterage; + byCompany.set(order.companyName, company); + const label = order_status_1.ORDER_STATUS_LABELS[order.status] ?? (0, order_status_1.toAdminStatus)(order.status); + byStatus.set(label, (byStatus.get(label) ?? 0) + 1); + } + return { + reportSalesByCompany: Array.from(byCompany.values()).sort((a, b) => b.totalAmount - a.totalAmount), + reportOrdersByStatus: Array.from(byStatus.entries()).map(([status, count]) => ({ status, count })), + }; + } + buildCheckDeadlines(checks, startOfToday) { + const buckets = [ + { id: 'cd-today', label: 'امروز', tone: 'danger', days: 0 }, + { id: 'cd-3', label: '۳ روز آینده', tone: 'warning', days: 3 }, + { id: 'cd-7', label: '۷ روز آینده', tone: 'warning', days: 7 }, + { id: 'cd-30', label: '۳۰ روز آینده', tone: 'neutral', days: 30 }, + ]; + return buckets.map((bucket) => { + const end = new Date(startOfToday); + end.setDate(end.getDate() + bucket.days); + end.setHours(23, 59, 59, 999); + const matched = checks.filter((c) => { + const d = new Date(c.dueDate); + d.setHours(0, 0, 0, 0); + if (bucket.days === 0) { + return d.getTime() === startOfToday.getTime(); + } + return d >= startOfToday && d <= end; + }); + return { + id: bucket.id, + label: bucket.label, + tone: bucket.tone, + count: matched.length, + amount: matched.reduce((s, c) => s + c.amount, 0), + }; + }); + } +}; +exports.DashboardService = DashboardService; +exports.DashboardService = DashboardService = __decorate([ + (0, common_1.Injectable)(), + __metadata("design:paramtypes", [prisma_service_1.PrismaService, + orders_service_1.OrdersService]) +], DashboardService); +//# sourceMappingURL=dashboard.service.js.map \ No newline at end of file diff --git a/dist/dashboard/dashboard.service.js.map b/dist/dashboard/dashboard.service.js.map new file mode 100644 index 0000000..36b579b --- /dev/null +++ b/dist/dashboard/dashboard.service.js.map @@ -0,0 +1 @@ +{"version":3,"file":"dashboard.service.js","sourceRoot":"","sources":["../../src/dashboard/dashboard.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,6DAAyD;AACzD,+DAIsC;AACtC,6DAAyD;AAGlD,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAER;IACA;IAFnB,YACmB,MAAqB,EACrB,aAA4B;QAD5B,WAAM,GAAN,MAAM,CAAe;QACrB,kBAAa,GAAb,aAAa,CAAe;IAC5C,CAAC;IAEJ,KAAK,CAAC,YAAY;QAChB,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,YAAY,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC;QACnC,YAAY,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAClC,MAAM,gBAAgB,GAAG,IAAI,IAAI,CAAC,Y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,CAAC,CAAC,CAAC;YAEH,OAAO;gBACL,EAAE,EAAE,MAAM,CAAC,EAAE;gBACb,KAAK,EAAE,MAAM,CAAC,KAAK;gBACnB,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,KAAK,EAAE,OAAO,CAAC,MAAM;gBACrB,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;aAClD,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAtPY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;qCAGgB,8BAAa;QACN,8BAAa;GAHpC,gBAAgB,CAsP5B"} \ No newline at end of file diff --git a/dist/main.d.ts b/dist/main.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/dist/main.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/main.js b/dist/main.js new file mode 100644 index 0000000..a3e946e --- /dev/null +++ b/dist/main.js @@ -0,0 +1,34 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const core_1 = require("@nestjs/core"); +const common_1 = require("@nestjs/common"); +const swagger_1 = require("@nestjs/swagger"); +const app_module_1 = require("./app.module"); +async function bootstrap() { + const app = await core_1.NestFactory.create(app_module_1.AppModule); + app.setGlobalPrefix('api'); + app.enableCors({ + origin: true, + credentials: true, + }); + app.useGlobalPipes(new common_1.ValidationPipe({ + whitelist: true, + transform: true, + forbidNonWhitelisted: true, + transformOptions: { enableImplicitConversion: true }, + })); + const swaggerConfig = new swagger_1.DocumentBuilder() + .setTitle('Fabric Trade API') + .setDescription('API سرور تجارت پارچه') + .setVersion('1.0') + .addBearerAuth() + .build(); + const document = swagger_1.SwaggerModule.createDocument(app, swaggerConfig); + swagger_1.SwaggerModule.setup('api/docs', app, document); + const port = process.env.PORT ?? 3000; + await app.listen(port); + console.log(`Fabric Trade API listening on http://localhost:${port}/api`); + console.log(`Swagger docs at http://localhost:${port}/api/docs`); +} +bootstrap(); +//# sourceMappingURL=main.js.map \ No newline at end of file diff --git a/dist/main.js.map b/dist/main.js.map new file mode 100644 index 0000000..fa728e8 --- /dev/null +++ b/dist/main.js.map @@ -0,0 +1 @@ +{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;AAAA,uCAA2C;AAC3C,2CAAgD;AAChD,6CAAiE;AACjE,6CAAyC;AAEzC,KAAK,UAAU,SAAS;IACtB,MAAM,GAAG,GAAG,MAAM,kBAAW,CAAC,MAAM,CAAC,sBAAS,CAAC,CAAC;IAEhD,GAAG,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IAC3B,GAAG,CAAC,UAAU,CAAC;QACb,MAAM,EAAE,IAAI;QACZ,WAAW,EAAE,IAAI;KAClB,CAAC,CAAC;IACH,GAAG,CAAC,cAAc,CAChB,IAAI,uBAAc,CAAC;QACjB,SAAS,EAAE,IAAI;QACf,SAAS,EAAE,IAAI;QACf,oBAAoB,EAAE,IAAI;QAC1B,gBAAgB,EAAE,EAAE,wBAAwB,EAAE,IAAI,EAAE;KACrD,CAAC,CACH,CAAC;IAEF,MAAM,aAAa,GAAG,IAAI,yBAAe,EAAE;SACxC,QAAQ,CAAC,kBAAkB,CAAC;SAC5B,cAAc,CAAC,sBAAsB,CAAC;SACtC,UAAU,CAAC,KAAK,CAAC;SACjB,aAAa,EAAE;SACf,KAAK,EAAE,CAAC;IACX,MAAM,QAAQ,GAAG,uBAAa,CAAC,cAAc,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC;IAClE,uBAAa,CAAC,KAAK,CAAC,UAAU,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC;IAE/C,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC;IACtC,MAAM,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACvB,OAAO,CAAC,GAAG,CAAC,kDAAkD,IAAI,MAAM,CAAC,CAAC;IAC1E,OAAO,CAAC,GAAG,CAAC,oCAAoC,IAAI,WAAW,CAAC,CAAC;AACnE,CAAC;AACD,SAAS,EAAE,CAAC"} \ No newline at end of file diff --git a/dist/orders/dto/order.dto.d.ts b/dist/orders/dto/order.dto.d.ts new file mode 100644 index 0000000..fd98e80 --- /dev/null +++ b/dist/orders/dto/order.dto.d.ts @@ -0,0 +1,62 @@ +import { CheckRegistrationMode, OrderStatus, SettlementType } from '@prisma/client'; +export declare class SubmitOrderItemDto { + productId: string; + meterage: number; + notes?: string; +} +export declare class SubmitOrderCheckDto { + amount: number; + dueDate: string; + sayadId?: string; + checkNumber?: string; + ownerNationalId?: string; + ownerFirstName?: string; + ownerLastName?: string; + bankName?: string; + branchName?: string; + frontImage?: string; + backImage?: string; + notes?: string; + mode?: CheckRegistrationMode; +} +export declare class SubmitOrderDto { + companyId: string; + settlementType: SettlementType; + checkMode?: CheckRegistrationMode; + notes?: string; + items: SubmitOrderItemDto[]; + checks?: SubmitOrderCheckDto[]; +} +export declare class AdminCreateOrderDto { + userId?: string; + customerPhone?: string; + customerName?: string; + companyId: string; + settlementType?: SettlementType; + settlementMethod?: SettlementType; + meterage?: number; + notes?: string; + items?: SubmitOrderItemDto[]; +} +export declare class OrderItemPricingDto { + id: string; + confirmedMeterage?: number; + unitPrice?: number; + supplyPrice?: number; + unitDiscount?: number; +} +export declare class UpdateOrderPricingDto { + items: OrderItemPricingDto[]; + shippingCost?: number; + totalDiscount?: number; + note?: string; +} +export declare class UpdateOrderStatusDto { + status: OrderStatus; + note?: string; + reason?: string; +} +export declare class UpdateOrderChecksDto { + checks: SubmitOrderCheckDto[]; + checkMode?: CheckRegistrationMode; +} diff --git a/dist/orders/dto/order.dto.js b/dist/orders/dto/order.dto.js new file mode 100644 index 0000000..9bde9c1 --- /dev/null +++ b/dist/orders/dto/order.dto.js @@ -0,0 +1,327 @@ +"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.UpdateOrderChecksDto = exports.UpdateOrderStatusDto = exports.UpdateOrderPricingDto = exports.OrderItemPricingDto = exports.AdminCreateOrderDto = exports.SubmitOrderDto = exports.SubmitOrderCheckDto = exports.SubmitOrderItemDto = void 0; +const class_validator_1 = require("class-validator"); +const class_transformer_1 = require("class-transformer"); +const client_1 = require("@prisma/client"); +class SubmitOrderItemDto { + productId; + meterage; + notes; +} +exports.SubmitOrderItemDto = SubmitOrderItemDto; +__decorate([ + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], SubmitOrderItemDto.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) +], SubmitOrderItemDto.prototype, "meterage", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], SubmitOrderItemDto.prototype, "notes", void 0); +class SubmitOrderCheckDto { + amount; + dueDate; + sayadId; + checkNumber; + ownerNationalId; + ownerFirstName; + ownerLastName; + bankName; + branchName; + frontImage; + backImage; + notes; + mode; +} +exports.SubmitOrderCheckDto = SubmitOrderCheckDto; +__decorate([ + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsNumber)(), + (0, class_validator_1.Min)(1), + __metadata("design:type", Number) +], SubmitOrderCheckDto.prototype, "amount", void 0); +__decorate([ + (0, class_validator_1.IsDateString)(), + __metadata("design:type", String) +], SubmitOrderCheckDto.prototype, "dueDate", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], SubmitOrderCheckDto.prototype, "sayadId", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], SubmitOrderCheckDto.prototype, "checkNumber", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], SubmitOrderCheckDto.prototype, "ownerNationalId", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], SubmitOrderCheckDto.prototype, "ownerFirstName", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], SubmitOrderCheckDto.prototype, "ownerLastName", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], SubmitOrderCheckDto.prototype, "bankName", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], SubmitOrderCheckDto.prototype, "branchName", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], SubmitOrderCheckDto.prototype, "frontImage", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], SubmitOrderCheckDto.prototype, "backImage", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], SubmitOrderCheckDto.prototype, "notes", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsEnum)(client_1.CheckRegistrationMode), + __metadata("design:type", String) +], SubmitOrderCheckDto.prototype, "mode", void 0); +class SubmitOrderDto { + companyId; + settlementType; + checkMode; + notes; + items; + checks; +} +exports.SubmitOrderDto = SubmitOrderDto; +__decorate([ + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], SubmitOrderDto.prototype, "companyId", void 0); +__decorate([ + (0, class_validator_1.IsEnum)(client_1.SettlementType), + __metadata("design:type", String) +], SubmitOrderDto.prototype, "settlementType", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsEnum)(client_1.CheckRegistrationMode), + __metadata("design:type", String) +], SubmitOrderDto.prototype, "checkMode", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], SubmitOrderDto.prototype, "notes", void 0); +__decorate([ + (0, class_validator_1.IsArray)(), + (0, class_validator_1.ArrayMinSize)(1), + (0, class_validator_1.ValidateNested)({ each: true }), + (0, class_transformer_1.Type)(() => SubmitOrderItemDto), + __metadata("design:type", Array) +], SubmitOrderDto.prototype, "items", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsArray)(), + (0, class_validator_1.ValidateNested)({ each: true }), + (0, class_transformer_1.Type)(() => SubmitOrderCheckDto), + __metadata("design:type", Array) +], SubmitOrderDto.prototype, "checks", void 0); +class AdminCreateOrderDto { + userId; + customerPhone; + customerName; + companyId; + settlementType; + settlementMethod; + meterage; + notes; + items; +} +exports.AdminCreateOrderDto = AdminCreateOrderDto; +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], AdminCreateOrderDto.prototype, "userId", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], AdminCreateOrderDto.prototype, "customerPhone", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], AdminCreateOrderDto.prototype, "customerName", void 0); +__decorate([ + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], AdminCreateOrderDto.prototype, "companyId", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsEnum)(client_1.SettlementType), + __metadata("design:type", String) +], AdminCreateOrderDto.prototype, "settlementType", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsEnum)(client_1.SettlementType), + __metadata("design:type", String) +], AdminCreateOrderDto.prototype, "settlementMethod", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsNumber)(), + (0, class_validator_1.Min)(0), + __metadata("design:type", Number) +], AdminCreateOrderDto.prototype, "meterage", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], AdminCreateOrderDto.prototype, "notes", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsArray)(), + (0, class_validator_1.ValidateNested)({ each: true }), + (0, class_transformer_1.Type)(() => SubmitOrderItemDto), + __metadata("design:type", Array) +], AdminCreateOrderDto.prototype, "items", void 0); +class OrderItemPricingDto { + id; + confirmedMeterage; + unitPrice; + supplyPrice; + unitDiscount; +} +exports.OrderItemPricingDto = OrderItemPricingDto; +__decorate([ + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], OrderItemPricingDto.prototype, "id", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsNumber)(), + (0, class_validator_1.Min)(0), + __metadata("design:type", Number) +], OrderItemPricingDto.prototype, "confirmedMeterage", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsNumber)(), + (0, class_validator_1.Min)(0), + __metadata("design:type", Number) +], OrderItemPricingDto.prototype, "unitPrice", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsNumber)(), + (0, class_validator_1.Min)(0), + __metadata("design:type", Number) +], OrderItemPricingDto.prototype, "supplyPrice", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsNumber)(), + (0, class_validator_1.Min)(0), + __metadata("design:type", Number) +], OrderItemPricingDto.prototype, "unitDiscount", void 0); +class UpdateOrderPricingDto { + items; + shippingCost; + totalDiscount; + note; +} +exports.UpdateOrderPricingDto = UpdateOrderPricingDto; +__decorate([ + (0, class_validator_1.IsArray)(), + (0, class_validator_1.ValidateNested)({ each: true }), + (0, class_transformer_1.Type)(() => OrderItemPricingDto), + __metadata("design:type", Array) +], UpdateOrderPricingDto.prototype, "items", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsNumber)(), + (0, class_validator_1.Min)(0), + __metadata("design:type", Number) +], UpdateOrderPricingDto.prototype, "shippingCost", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsNumber)(), + (0, class_validator_1.Min)(0), + __metadata("design:type", Number) +], UpdateOrderPricingDto.prototype, "totalDiscount", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], UpdateOrderPricingDto.prototype, "note", void 0); +class UpdateOrderStatusDto { + status; + note; + reason; +} +exports.UpdateOrderStatusDto = UpdateOrderStatusDto; +__decorate([ + (0, class_validator_1.IsEnum)(client_1.OrderStatus), + __metadata("design:type", String) +], UpdateOrderStatusDto.prototype, "status", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], UpdateOrderStatusDto.prototype, "note", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], UpdateOrderStatusDto.prototype, "reason", void 0); +class UpdateOrderChecksDto { + checks; + checkMode; +} +exports.UpdateOrderChecksDto = UpdateOrderChecksDto; +__decorate([ + (0, class_validator_1.IsArray)(), + (0, class_validator_1.ValidateNested)({ each: true }), + (0, class_transformer_1.Type)(() => SubmitOrderCheckDto), + __metadata("design:type", Array) +], UpdateOrderChecksDto.prototype, "checks", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsEnum)(client_1.CheckRegistrationMode), + __metadata("design:type", String) +], UpdateOrderChecksDto.prototype, "checkMode", void 0); +//# sourceMappingURL=order.dto.js.map \ No newline at end of file diff --git a/dist/orders/dto/order.dto.js.map b/dist/orders/dto/order.dto.js.map new file mode 100644 index 0000000..c46706f --- /dev/null +++ b/dist/orders/dto/order.dto.js.map @@ -0,0 +1 @@ +{"version":3,"file":"order.dto.js","sourceRoot":"","sources":["../../../src/orders/dto/order.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAUyB;AACzB,yDAAyC;AACzC,2CAIwB;AAExB,MAAa,kBAAkB;IAE7B,SAAS,CAAU;IAKnB,QAAQ,CAAU;IAIlB,KAAK,CAAU;CAChB;AAZD,gDAYC;AAVC;IADC,IAAA,0BAAQ,GAAE;;qDACQ;AAKnB;IAHC,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC;IAClB,IAAA,0BAAQ,GAAE;IACV,IAAA,qBAAG,EAAC,KAAK,CAAC;;oDACO;AAIlB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;iDACI;AAGjB,MAAa,mBAAmB;IAI9B,MAAM,CAAU;IAGhB,OAAO,CAAU;IAIjB,OAAO,CAAU;IAIjB,WAAW,CAAU;IAIrB,eAAe,CAAU;IAIzB,cAAc,CAAU;IAIxB,aAAa,CAAU;IAIvB,QAAQ,CAAU;IAIlB,UAAU,CAAU;IAIpB,UAAU,CAAU;IAIpB,SAAS,CAAU;IAInB,KAAK,CAAU;IAIf,IAAI,CAAyB;CAC9B;AApDD,kDAoDC;AAhDC;IAHC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I,EAAE,IAAI,EAAE,CAAC;IAC9B,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,mBAAmB,CAAC;;oDACF;AAM9B;IAJC,IAAA,4BAAU,GAAE;IACZ,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC;IAClB,IAAA,0BAAQ,GAAE;IACV,IAAA,qBAAG,EAAC,CAAC,CAAC;;2DACe;AAMtB;IAJC,IAAA,4BAAU,GAAE;IACZ,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC;IAClB,IAAA,0BAAQ,GAAE;IACV,IAAA,qBAAG,EAAC,CAAC,CAAC;;4DACgB;AAIvB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;mDACG;AAGhB,MAAa,oBAAoB;IAE/B,MAAM,CAAe;IAIrB,IAAI,CAAU;IAId,MAAM,CAAU;CACjB;AAXD,oDAWC;AATC;IADC,IAAA,wBAAM,EAAC,oBAAW,CAAC;;oDACC;AAIrB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;kDACG;AAId;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;oDACK;AAGlB,MAAa,oBAAoB;IAI/B,MAAM,CAAyB;IAI/B,SAAS,CAAyB;CACnC;AATD,oDASC;AALC;IAHC,IAAA,yBAAO,GAAE;IACT,IAAA,gCAAc,EAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAC9B,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,mBAAmB,CAAC;;oDACD;AAI/B;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,wBAAM,EAAC,8BAAqB,CAAC;;uDACI"} \ No newline at end of file diff --git a/dist/orders/orders.controller.d.ts b/dist/orders/orders.controller.d.ts new file mode 100644 index 0000000..844c7d2 --- /dev/null +++ b/dist/orders/orders.controller.d.ts @@ -0,0 +1,920 @@ +import { OrdersService } from './orders.service'; +import type { AuthPrincipal } from '../common/decorators/current-user.decorator'; +import { AdminCreateOrderDto, SubmitOrderDto, UpdateOrderChecksDto, UpdateOrderPricingDto, UpdateOrderStatusDto } from './dto/order.dto'; +export declare class CustomerOrdersController { + private readonly ordersService; + constructor(ordersService: OrdersService); + findMine(user: AuthPrincipal): Promise<{ + id: string; + orderNumber: string; + userId: string; + companyId: string; + companyName: string; + settlementType: import("@prisma/client").$Enums.SettlementType; + settlementMethod: import("@prisma/client").$Enums.SettlementType; + checkMode: import("@prisma/client").$Enums.CheckRegistrationMode | undefined; + status: import("@prisma/client").$Enums.OrderStatus; + adminStatus: string; + totalMeterage: number; + meterage: number; + totalAmount: number | null; + shippingCost: number | null; + totalDiscount: number | null; + finalAmount: number | null; + notes: string | undefined; + checkRassDays: number | undefined; + checkRassDate: string | undefined; + cashInvoiceExpiresAt: string | undefined; + createdAt: string; + updatedAt: string; + customerName: string; + customerPhone: string; + customerNationalId: string | undefined; + customerType: import("@prisma/client").$Enums.CustomerType; + items: { + id: string; + productId: string | undefined; + catalogCode: string; + productName: string; + productCode: string | undefined; + color: string; + requestedMeterage: number; + confirmedMeterage: number | null; + unitPrice: number | null; + supplyPrice: number | null; + unitDiscount: number; + discount: number; + lineTotal: number | null; + totalAmount: number | null; + notes: string | undefined; + }[]; + checks: { + id: string; + orderId: string; + row: number; + amount: number; + dueDate: string; + sayadId: string | undefined; + checkNumber: string | undefined; + ownerNationalId: string | undefined; + ownerFirstName: string | undefined; + ownerLastName: string | undefined; + bankName: string; + branchName: string | undefined; + frontImage: string | undefined; + backImage: string | undefined; + notes: string | undefined; + mode: import("@prisma/client").$Enums.CheckRegistrationMode; + status: import("@prisma/client").$Enums.CheckStatus; + createdAt: string; + updatedAt: string; + }[]; + cashReceipt: { + id: string; + amount: number; + paidAmount: number | null; + transferDate: string | null; + transferTime: string | undefined; + trackingNumber: string | undefined; + trackingCode: string | undefined; + destinationAccountId: string | undefined; + receiptImage: string | undefined; + notes: string | undefined; + expiresAt: string | undefined; + status: import("@prisma/client").$Enums.CashPaymentStatus; + submittedAt: string | undefined; + createdAt: string; + } | undefined; + shipment: { + id: string; + orderId: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + } | undefined; + statusHistory: { + id: string; + fromStatus: import("@prisma/client").$Enums.OrderStatus | null; + toStatus: import("@prisma/client").$Enums.OrderStatus; + changedBy: string; + note: string | undefined; + reason: string | undefined; + changedAt: string; + }[]; + }[]>; + findOne(user: AuthPrincipal, id: string): Promise<{ + id: string; + orderNumber: string; + userId: string; + companyId: string; + companyName: string; + settlementType: import("@prisma/client").$Enums.SettlementType; + settlementMethod: import("@prisma/client").$Enums.SettlementType; + checkMode: import("@prisma/client").$Enums.CheckRegistrationMode | undefined; + status: import("@prisma/client").$Enums.OrderStatus; + adminStatus: string; + totalMeterage: number; + meterage: number; + totalAmount: number | null; + shippingCost: number | null; + totalDiscount: number | null; + finalAmount: number | null; + notes: string | undefined; + checkRassDays: number | undefined; + checkRassDate: string | undefined; + cashInvoiceExpiresAt: string | undefined; + createdAt: string; + updatedAt: string; + customerName: string; + customerPhone: string; + customerNationalId: string | undefined; + customerType: import("@prisma/client").$Enums.CustomerType; + items: { + id: string; + productId: string | undefined; + catalogCode: string; + productName: string; + productCode: string | undefined; + color: string; + requestedMeterage: number; + confirmedMeterage: number | null; + unitPrice: number | null; + supplyPrice: number | null; + unitDiscount: number; + discount: number; + lineTotal: number | null; + totalAmount: number | null; + notes: string | undefined; + }[]; + checks: { + id: string; + orderId: string; + row: number; + amount: number; + dueDate: string; + sayadId: string | undefined; + checkNumber: string | undefined; + ownerNationalId: string | undefined; + ownerFirstName: string | undefined; + ownerLastName: string | undefined; + bankName: string; + branchName: string | undefined; + frontImage: string | undefined; + backImage: string | undefined; + notes: string | undefined; + mode: import("@prisma/client").$Enums.CheckRegistrationMode; + status: import("@prisma/client").$Enums.CheckStatus; + createdAt: string; + updatedAt: string; + }[]; + cashReceipt: { + id: string; + amount: number; + paidAmount: number | null; + transferDate: string | null; + transferTime: string | undefined; + trackingNumber: string | undefined; + trackingCode: string | undefined; + destinationAccountId: string | undefined; + receiptImage: string | undefined; + notes: string | undefined; + expiresAt: string | undefined; + status: import("@prisma/client").$Enums.CashPaymentStatus; + submittedAt: string | undefined; + createdAt: string; + } | undefined; + shipment: { + id: string; + orderId: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + } | undefined; + statusHistory: { + id: string; + fromStatus: import("@prisma/client").$Enums.OrderStatus | null; + toStatus: import("@prisma/client").$Enums.OrderStatus; + changedBy: string; + note: string | undefined; + reason: string | undefined; + changedAt: string; + }[]; + }>; + submit(user: AuthPrincipal, dto: SubmitOrderDto): Promise<{ + id: string; + orderNumber: string; + userId: string; + companyId: string; + companyName: string; + settlementType: import("@prisma/client").$Enums.SettlementType; + settlementMethod: import("@prisma/client").$Enums.SettlementType; + checkMode: import("@prisma/client").$Enums.CheckRegistrationMode | undefined; + status: import("@prisma/client").$Enums.OrderStatus; + adminStatus: string; + totalMeterage: number; + meterage: number; + totalAmount: number | null; + shippingCost: number | null; + totalDiscount: number | null; + finalAmount: number | null; + notes: string | undefined; + checkRassDays: number | undefined; + checkRassDate: string | undefined; + cashInvoiceExpiresAt: string | undefined; + createdAt: string; + updatedAt: string; + customerName: string; + customerPhone: string; + customerNationalId: string | undefined; + customerType: import("@prisma/client").$Enums.CustomerType; + items: { + id: string; + productId: string | undefined; + catalogCode: string; + productName: string; + productCode: string | undefined; + color: string; + requestedMeterage: number; + confirmedMeterage: number | null; + unitPrice: number | null; + supplyPrice: number | null; + unitDiscount: number; + discount: number; + lineTotal: number | null; + totalAmount: number | null; + notes: string | undefined; + }[]; + checks: { + id: string; + orderId: string; + row: number; + amount: number; + dueDate: string; + sayadId: string | undefined; + checkNumber: string | undefined; + ownerNationalId: string | undefined; + ownerFirstName: string | undefined; + ownerLastName: string | undefined; + bankName: string; + branchName: string | undefined; + frontImage: string | undefined; + backImage: string | undefined; + notes: string | undefined; + mode: import("@prisma/client").$Enums.CheckRegistrationMode; + status: import("@prisma/client").$Enums.CheckStatus; + createdAt: string; + updatedAt: string; + }[]; + cashReceipt: { + id: string; + amount: number; + paidAmount: number | null; + transferDate: string | null; + transferTime: string | undefined; + trackingNumber: string | undefined; + trackingCode: string | undefined; + destinationAccountId: string | undefined; + receiptImage: string | undefined; + notes: string | undefined; + expiresAt: string | undefined; + status: import("@prisma/client").$Enums.CashPaymentStatus; + submittedAt: string | undefined; + createdAt: string; + } | undefined; + shipment: { + id: string; + orderId: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + } | undefined; + statusHistory: { + id: string; + fromStatus: import("@prisma/client").$Enums.OrderStatus | null; + toStatus: import("@prisma/client").$Enums.OrderStatus; + changedBy: string; + note: string | undefined; + reason: string | undefined; + changedAt: string; + }[]; + }>; + updateChecks(user: AuthPrincipal, id: string, dto: UpdateOrderChecksDto): Promise<{ + id: string; + orderNumber: string; + userId: string; + companyId: string; + companyName: string; + settlementType: import("@prisma/client").$Enums.SettlementType; + settlementMethod: import("@prisma/client").$Enums.SettlementType; + checkMode: import("@prisma/client").$Enums.CheckRegistrationMode | undefined; + status: import("@prisma/client").$Enums.OrderStatus; + adminStatus: string; + totalMeterage: number; + meterage: number; + totalAmount: number | null; + shippingCost: number | null; + totalDiscount: number | null; + finalAmount: number | null; + notes: string | undefined; + checkRassDays: number | undefined; + checkRassDate: string | undefined; + cashInvoiceExpiresAt: string | undefined; + createdAt: string; + updatedAt: string; + customerName: string; + customerPhone: string; + customerNationalId: string | undefined; + customerType: import("@prisma/client").$Enums.CustomerType; + items: { + id: string; + productId: string | undefined; + catalogCode: string; + productName: string; + productCode: string | undefined; + color: string; + requestedMeterage: number; + confirmedMeterage: number | null; + unitPrice: number | null; + supplyPrice: number | null; + unitDiscount: number; + discount: number; + lineTotal: number | null; + totalAmount: number | null; + notes: string | undefined; + }[]; + checks: { + id: string; + orderId: string; + row: number; + amount: number; + dueDate: string; + sayadId: string | undefined; + checkNumber: string | undefined; + ownerNationalId: string | undefined; + ownerFirstName: string | undefined; + ownerLastName: string | undefined; + bankName: string; + branchName: string | undefined; + frontImage: string | undefined; + backImage: string | undefined; + notes: string | undefined; + mode: import("@prisma/client").$Enums.CheckRegistrationMode; + status: import("@prisma/client").$Enums.CheckStatus; + createdAt: string; + updatedAt: string; + }[]; + cashReceipt: { + id: string; + amount: number; + paidAmount: number | null; + transferDate: string | null; + transferTime: string | undefined; + trackingNumber: string | undefined; + trackingCode: string | undefined; + destinationAccountId: string | undefined; + receiptImage: string | undefined; + notes: string | undefined; + expiresAt: string | undefined; + status: import("@prisma/client").$Enums.CashPaymentStatus; + submittedAt: string | undefined; + createdAt: string; + } | undefined; + shipment: { + id: string; + orderId: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + } | undefined; + statusHistory: { + id: string; + fromStatus: import("@prisma/client").$Enums.OrderStatus | null; + toStatus: import("@prisma/client").$Enums.OrderStatus; + changedBy: string; + note: string | undefined; + reason: string | undefined; + changedAt: string; + }[]; + }>; +} +export declare class AdminOrdersController { + private readonly ordersService; + constructor(ordersService: OrdersService); + findAll(status?: string, q?: string): Promise<{ + id: string; + orderNumber: string; + userId: string; + companyId: string; + companyName: string; + settlementType: import("@prisma/client").$Enums.SettlementType; + settlementMethod: import("@prisma/client").$Enums.SettlementType; + checkMode: import("@prisma/client").$Enums.CheckRegistrationMode | undefined; + status: import("@prisma/client").$Enums.OrderStatus; + adminStatus: string; + totalMeterage: number; + meterage: number; + totalAmount: number | null; + shippingCost: number | null; + totalDiscount: number | null; + finalAmount: number | null; + notes: string | undefined; + checkRassDays: number | undefined; + checkRassDate: string | undefined; + cashInvoiceExpiresAt: string | undefined; + createdAt: string; + updatedAt: string; + customerName: string; + customerPhone: string; + customerNationalId: string | undefined; + customerType: import("@prisma/client").$Enums.CustomerType; + items: { + id: string; + productId: string | undefined; + catalogCode: string; + productName: string; + productCode: string | undefined; + color: string; + requestedMeterage: number; + confirmedMeterage: number | null; + unitPrice: number | null; + supplyPrice: number | null; + unitDiscount: number; + discount: number; + lineTotal: number | null; + totalAmount: number | null; + notes: string | undefined; + }[]; + checks: { + id: string; + orderId: string; + row: number; + amount: number; + dueDate: string; + sayadId: string | undefined; + checkNumber: string | undefined; + ownerNationalId: string | undefined; + ownerFirstName: string | undefined; + ownerLastName: string | undefined; + bankName: string; + branchName: string | undefined; + frontImage: string | undefined; + backImage: string | undefined; + notes: string | undefined; + mode: import("@prisma/client").$Enums.CheckRegistrationMode; + status: import("@prisma/client").$Enums.CheckStatus; + createdAt: string; + updatedAt: string; + }[]; + cashReceipt: { + id: string; + amount: number; + paidAmount: number | null; + transferDate: string | null; + transferTime: string | undefined; + trackingNumber: string | undefined; + trackingCode: string | undefined; + destinationAccountId: string | undefined; + receiptImage: string | undefined; + notes: string | undefined; + expiresAt: string | undefined; + status: import("@prisma/client").$Enums.CashPaymentStatus; + submittedAt: string | undefined; + createdAt: string; + } | undefined; + shipment: { + id: string; + orderId: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + } | undefined; + statusHistory: { + id: string; + fromStatus: import("@prisma/client").$Enums.OrderStatus | null; + toStatus: import("@prisma/client").$Enums.OrderStatus; + changedBy: string; + note: string | undefined; + reason: string | undefined; + changedAt: string; + }[]; + }[]>; + findOne(id: string): Promise<{ + id: string; + orderNumber: string; + userId: string; + companyId: string; + companyName: string; + settlementType: import("@prisma/client").$Enums.SettlementType; + settlementMethod: import("@prisma/client").$Enums.SettlementType; + checkMode: import("@prisma/client").$Enums.CheckRegistrationMode | undefined; + status: import("@prisma/client").$Enums.OrderStatus; + adminStatus: string; + totalMeterage: number; + meterage: number; + totalAmount: number | null; + shippingCost: number | null; + totalDiscount: number | null; + finalAmount: number | null; + notes: string | undefined; + checkRassDays: number | undefined; + checkRassDate: string | undefined; + cashInvoiceExpiresAt: string | undefined; + createdAt: string; + updatedAt: string; + customerName: string; + customerPhone: string; + customerNationalId: string | undefined; + customerType: import("@prisma/client").$Enums.CustomerType; + items: { + id: string; + productId: string | undefined; + catalogCode: string; + productName: string; + productCode: string | undefined; + color: string; + requestedMeterage: number; + confirmedMeterage: number | null; + unitPrice: number | null; + supplyPrice: number | null; + unitDiscount: number; + discount: number; + lineTotal: number | null; + totalAmount: number | null; + notes: string | undefined; + }[]; + checks: { + id: string; + orderId: string; + row: number; + amount: number; + dueDate: string; + sayadId: string | undefined; + checkNumber: string | undefined; + ownerNationalId: string | undefined; + ownerFirstName: string | undefined; + ownerLastName: string | undefined; + bankName: string; + branchName: string | undefined; + frontImage: string | undefined; + backImage: string | undefined; + notes: string | undefined; + mode: import("@prisma/client").$Enums.CheckRegistrationMode; + status: import("@prisma/client").$Enums.CheckStatus; + createdAt: string; + updatedAt: string; + }[]; + cashReceipt: { + id: string; + amount: number; + paidAmount: number | null; + transferDate: string | null; + transferTime: string | undefined; + trackingNumber: string | undefined; + trackingCode: string | undefined; + destinationAccountId: string | undefined; + receiptImage: string | undefined; + notes: string | undefined; + expiresAt: string | undefined; + status: import("@prisma/client").$Enums.CashPaymentStatus; + submittedAt: string | undefined; + createdAt: string; + } | undefined; + shipment: { + id: string; + orderId: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + } | undefined; + statusHistory: { + id: string; + fromStatus: import("@prisma/client").$Enums.OrderStatus | null; + toStatus: import("@prisma/client").$Enums.OrderStatus; + changedBy: string; + note: string | undefined; + reason: string | undefined; + changedAt: string; + }[]; + }>; + create(user: AuthPrincipal, dto: AdminCreateOrderDto): Promise<{ + id: string; + orderNumber: string; + userId: string; + companyId: string; + companyName: string; + settlementType: import("@prisma/client").$Enums.SettlementType; + settlementMethod: import("@prisma/client").$Enums.SettlementType; + checkMode: import("@prisma/client").$Enums.CheckRegistrationMode | undefined; + status: import("@prisma/client").$Enums.OrderStatus; + adminStatus: string; + totalMeterage: number; + meterage: number; + totalAmount: number | null; + shippingCost: number | null; + totalDiscount: number | null; + finalAmount: number | null; + notes: string | undefined; + checkRassDays: number | undefined; + checkRassDate: string | undefined; + cashInvoiceExpiresAt: string | undefined; + createdAt: string; + updatedAt: string; + customerName: string; + customerPhone: string; + customerNationalId: string | undefined; + customerType: import("@prisma/client").$Enums.CustomerType; + items: { + id: string; + productId: string | undefined; + catalogCode: string; + productName: string; + productCode: string | undefined; + color: string; + requestedMeterage: number; + confirmedMeterage: number | null; + unitPrice: number | null; + supplyPrice: number | null; + unitDiscount: number; + discount: number; + lineTotal: number | null; + totalAmount: number | null; + notes: string | undefined; + }[]; + checks: { + id: string; + orderId: string; + row: number; + amount: number; + dueDate: string; + sayadId: string | undefined; + checkNumber: string | undefined; + ownerNationalId: string | undefined; + ownerFirstName: string | undefined; + ownerLastName: string | undefined; + bankName: string; + branchName: string | undefined; + frontImage: string | undefined; + backImage: string | undefined; + notes: string | undefined; + mode: import("@prisma/client").$Enums.CheckRegistrationMode; + status: import("@prisma/client").$Enums.CheckStatus; + createdAt: string; + updatedAt: string; + }[]; + cashReceipt: { + id: string; + amount: number; + paidAmount: number | null; + transferDate: string | null; + transferTime: string | undefined; + trackingNumber: string | undefined; + trackingCode: string | undefined; + destinationAccountId: string | undefined; + receiptImage: string | undefined; + notes: string | undefined; + expiresAt: string | undefined; + status: import("@prisma/client").$Enums.CashPaymentStatus; + submittedAt: string | undefined; + createdAt: string; + } | undefined; + shipment: { + id: string; + orderId: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + } | undefined; + statusHistory: { + id: string; + fromStatus: import("@prisma/client").$Enums.OrderStatus | null; + toStatus: import("@prisma/client").$Enums.OrderStatus; + changedBy: string; + note: string | undefined; + reason: string | undefined; + changedAt: string; + }[]; + }>; + updatePricing(user: AuthPrincipal, id: string, dto: UpdateOrderPricingDto): Promise<{ + id: string; + orderNumber: string; + userId: string; + companyId: string; + companyName: string; + settlementType: import("@prisma/client").$Enums.SettlementType; + settlementMethod: import("@prisma/client").$Enums.SettlementType; + checkMode: import("@prisma/client").$Enums.CheckRegistrationMode | undefined; + status: import("@prisma/client").$Enums.OrderStatus; + adminStatus: string; + totalMeterage: number; + meterage: number; + totalAmount: number | null; + shippingCost: number | null; + totalDiscount: number | null; + finalAmount: number | null; + notes: string | undefined; + checkRassDays: number | undefined; + checkRassDate: string | undefined; + cashInvoiceExpiresAt: string | undefined; + createdAt: string; + updatedAt: string; + customerName: string; + customerPhone: string; + customerNationalId: string | undefined; + customerType: import("@prisma/client").$Enums.CustomerType; + items: { + id: string; + productId: string | undefined; + catalogCode: string; + productName: string; + productCode: string | undefined; + color: string; + requestedMeterage: number; + confirmedMeterage: number | null; + unitPrice: number | null; + supplyPrice: number | null; + unitDiscount: number; + discount: number; + lineTotal: number | null; + totalAmount: number | null; + notes: string | undefined; + }[]; + checks: { + id: string; + orderId: string; + row: number; + amount: number; + dueDate: string; + sayadId: string | undefined; + checkNumber: string | undefined; + ownerNationalId: string | undefined; + ownerFirstName: string | undefined; + ownerLastName: string | undefined; + bankName: string; + branchName: string | undefined; + frontImage: string | undefined; + backImage: string | undefined; + notes: string | undefined; + mode: import("@prisma/client").$Enums.CheckRegistrationMode; + status: import("@prisma/client").$Enums.CheckStatus; + createdAt: string; + updatedAt: string; + }[]; + cashReceipt: { + id: string; + amount: number; + paidAmount: number | null; + transferDate: string | null; + transferTime: string | undefined; + trackingNumber: string | undefined; + trackingCode: string | undefined; + destinationAccountId: string | undefined; + receiptImage: string | undefined; + notes: string | undefined; + expiresAt: string | undefined; + status: import("@prisma/client").$Enums.CashPaymentStatus; + submittedAt: string | undefined; + createdAt: string; + } | undefined; + shipment: { + id: string; + orderId: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + } | undefined; + statusHistory: { + id: string; + fromStatus: import("@prisma/client").$Enums.OrderStatus | null; + toStatus: import("@prisma/client").$Enums.OrderStatus; + changedBy: string; + note: string | undefined; + reason: string | undefined; + changedAt: string; + }[]; + }>; + updateStatus(user: AuthPrincipal, id: string, dto: UpdateOrderStatusDto): Promise<{ + id: string; + orderNumber: string; + userId: string; + companyId: string; + companyName: string; + settlementType: import("@prisma/client").$Enums.SettlementType; + settlementMethod: import("@prisma/client").$Enums.SettlementType; + checkMode: import("@prisma/client").$Enums.CheckRegistrationMode | undefined; + status: import("@prisma/client").$Enums.OrderStatus; + adminStatus: string; + totalMeterage: number; + meterage: number; + totalAmount: number | null; + shippingCost: number | null; + totalDiscount: number | null; + finalAmount: number | null; + notes: string | undefined; + checkRassDays: number | undefined; + checkRassDate: string | undefined; + cashInvoiceExpiresAt: string | undefined; + createdAt: string; + updatedAt: string; + customerName: string; + customerPhone: string; + customerNationalId: string | undefined; + customerType: import("@prisma/client").$Enums.CustomerType; + items: { + id: string; + productId: string | undefined; + catalogCode: string; + productName: string; + productCode: string | undefined; + color: string; + requestedMeterage: number; + confirmedMeterage: number | null; + unitPrice: number | null; + supplyPrice: number | null; + unitDiscount: number; + discount: number; + lineTotal: number | null; + totalAmount: number | null; + notes: string | undefined; + }[]; + checks: { + id: string; + orderId: string; + row: number; + amount: number; + dueDate: string; + sayadId: string | undefined; + checkNumber: string | undefined; + ownerNationalId: string | undefined; + ownerFirstName: string | undefined; + ownerLastName: string | undefined; + bankName: string; + branchName: string | undefined; + frontImage: string | undefined; + backImage: string | undefined; + notes: string | undefined; + mode: import("@prisma/client").$Enums.CheckRegistrationMode; + status: import("@prisma/client").$Enums.CheckStatus; + createdAt: string; + updatedAt: string; + }[]; + cashReceipt: { + id: string; + amount: number; + paidAmount: number | null; + transferDate: string | null; + transferTime: string | undefined; + trackingNumber: string | undefined; + trackingCode: string | undefined; + destinationAccountId: string | undefined; + receiptImage: string | undefined; + notes: string | undefined; + expiresAt: string | undefined; + status: import("@prisma/client").$Enums.CashPaymentStatus; + submittedAt: string | undefined; + createdAt: string; + } | undefined; + shipment: { + id: string; + orderId: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + } | undefined; + statusHistory: { + id: string; + fromStatus: import("@prisma/client").$Enums.OrderStatus | null; + toStatus: import("@prisma/client").$Enums.OrderStatus; + changedBy: string; + note: string | undefined; + reason: string | undefined; + changedAt: string; + }[]; + }>; +} diff --git a/dist/orders/orders.controller.js b/dist/orders/orders.controller.js new file mode 100644 index 0000000..19b8138 --- /dev/null +++ b/dist/orders/orders.controller.js @@ -0,0 +1,148 @@ +"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.AdminOrdersController = exports.CustomerOrdersController = void 0; +const common_1 = require("@nestjs/common"); +const orders_service_1 = require("./orders.service"); +const auth_decorators_1 = require("../common/decorators/auth.decorators"); +const current_user_decorator_1 = require("../common/decorators/current-user.decorator"); +const order_dto_1 = require("./dto/order.dto"); +let CustomerOrdersController = class CustomerOrdersController { + ordersService; + constructor(ordersService) { + this.ordersService = ordersService; + } + findMine(user) { + return this.ordersService.findMyOrders(user.id); + } + findOne(user, id) { + return this.ordersService.findMyOrder(user.id, id); + } + submit(user, dto) { + return this.ordersService.submitOrder(user.id, dto); + } + updateChecks(user, id, dto) { + return this.ordersService.updateChecks(user.id, id, dto); + } +}; +exports.CustomerOrdersController = CustomerOrdersController; +__decorate([ + (0, auth_decorators_1.AuthType)('customer'), + (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) +], CustomerOrdersController.prototype, "findMine", null); +__decorate([ + (0, auth_decorators_1.AuthType)('customer'), + (0, common_1.Get)(':id'), + __param(0, (0, current_user_decorator_1.CurrentUser)()), + __param(1, (0, common_1.Param)('id')), + __metadata("design:type", Function), + __metadata("design:paramtypes", [Object, String]), + __metadata("design:returntype", void 0) +], CustomerOrdersController.prototype, "findOne", null); +__decorate([ + (0, auth_decorators_1.AuthType)('customer'), + (0, common_1.Post)(), + __param(0, (0, current_user_decorator_1.CurrentUser)()), + __param(1, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [Object, order_dto_1.SubmitOrderDto]), + __metadata("design:returntype", void 0) +], CustomerOrdersController.prototype, "submit", null); +__decorate([ + (0, auth_decorators_1.AuthType)('customer'), + (0, common_1.Patch)(':id/checks'), + __param(0, (0, current_user_decorator_1.CurrentUser)()), + __param(1, (0, common_1.Param)('id')), + __param(2, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [Object, String, order_dto_1.UpdateOrderChecksDto]), + __metadata("design:returntype", void 0) +], CustomerOrdersController.prototype, "updateChecks", null); +exports.CustomerOrdersController = CustomerOrdersController = __decorate([ + (0, common_1.Controller)('orders'), + __metadata("design:paramtypes", [orders_service_1.OrdersService]) +], CustomerOrdersController); +let AdminOrdersController = class AdminOrdersController { + ordersService; + constructor(ordersService) { + this.ordersService = ordersService; + } + findAll(status, q) { + return this.ordersService.findAdminOrders({ status, q }); + } + findOne(id) { + return this.ordersService.findAdminOrder(id); + } + create(user, dto) { + return this.ordersService.adminCreate(user.id, dto); + } + updatePricing(user, id, dto) { + return this.ordersService.updatePricing(id, user.id, dto); + } + updateStatus(user, id, dto) { + return this.ordersService.updateStatus(id, user.id, dto); + } +}; +exports.AdminOrdersController = AdminOrdersController; +__decorate([ + (0, common_1.Get)(), + __param(0, (0, common_1.Query)('status')), + __param(1, (0, common_1.Query)('q')), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String, String]), + __metadata("design:returntype", void 0) +], AdminOrdersController.prototype, "findAll", null); +__decorate([ + (0, common_1.Get)(':id'), + __param(0, (0, common_1.Param)('id')), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String]), + __metadata("design:returntype", void 0) +], AdminOrdersController.prototype, "findOne", null); +__decorate([ + (0, common_1.Post)(), + __param(0, (0, current_user_decorator_1.CurrentUser)()), + __param(1, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [Object, order_dto_1.AdminCreateOrderDto]), + __metadata("design:returntype", void 0) +], AdminOrdersController.prototype, "create", null); +__decorate([ + (0, common_1.Patch)(':id/pricing'), + __param(0, (0, current_user_decorator_1.CurrentUser)()), + __param(1, (0, common_1.Param)('id')), + __param(2, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [Object, String, order_dto_1.UpdateOrderPricingDto]), + __metadata("design:returntype", void 0) +], AdminOrdersController.prototype, "updatePricing", null); +__decorate([ + (0, common_1.Patch)(':id/status'), + __param(0, (0, current_user_decorator_1.CurrentUser)()), + __param(1, (0, common_1.Param)('id')), + __param(2, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [Object, String, order_dto_1.UpdateOrderStatusDto]), + __metadata("design:returntype", void 0) +], AdminOrdersController.prototype, "updateStatus", null); +exports.AdminOrdersController = AdminOrdersController = __decorate([ + (0, common_1.Controller)('admin/orders'), + (0, auth_decorators_1.AuthType)('admin'), + __metadata("design:paramtypes", [orders_service_1.OrdersService]) +], AdminOrdersController); +//# sourceMappingURL=orders.controller.js.map \ No newline at end of file diff --git a/dist/orders/orders.controller.js.map b/dist/orders/orders.controller.js.map new file mode 100644 index 0000000..08d8793 --- /dev/null +++ b/dist/orders/orders.controller.js.map @@ -0,0 +1 @@ +{"version":3,"file":"orders.controller.js","sourceRoot":"","sources":["../../src/orders/orders.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAQwB;AACxB,qDAAiD;AACjD,0EAAgE;AAChE,wFAA0E;AAE1E,+CAMyB;AAGlB,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IACN;IAA7B,YAA6B,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;IAAG,CAAC;IAI7D,QAAQ,CAAgB,IAAmB;QACzC,OAAO,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAClD,CAAC;IAID,OAAO,CACU,IAAmB,EACrB,EAAU;QAEvB,OAAO,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACrD,CAAC;IAID,MAAM,CACW,IAAmB,EAC1B,GAAmB;QAE3B,OAAO,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IACtD,CAAC;IAID,YAAY,CACK,IAAmB,EACrB,EAAU,EACf,GAAyB;QAEjC,OAAO,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC,CAAC;IAC3D,CAAC;CACF,CAAA;AApCY,4DAAwB;AAKnC;IAFC,IAAA,0BAAQ,EAAC,UAAU,CAAC;IACpB,IAAA,YAAG,GAAE;IACI,WA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.module.d.ts b/dist/orders/orders.module.d.ts new file mode 100644 index 0000000..f497f6d --- /dev/null +++ b/dist/orders/orders.module.d.ts @@ -0,0 +1,2 @@ +export declare class OrdersModule { +} diff --git a/dist/orders/orders.module.js b/dist/orders/orders.module.js new file mode 100644 index 0000000..13befbf --- /dev/null +++ b/dist/orders/orders.module.js @@ -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.OrdersModule = void 0; +const common_1 = require("@nestjs/common"); +const orders_controller_1 = require("./orders.controller"); +const orders_service_1 = require("./orders.service"); +let OrdersModule = class OrdersModule { +}; +exports.OrdersModule = OrdersModule; +exports.OrdersModule = OrdersModule = __decorate([ + (0, common_1.Module)({ + controllers: [orders_controller_1.CustomerOrdersController, orders_controller_1.AdminOrdersController], + providers: [orders_service_1.OrdersService], + exports: [orders_service_1.OrdersService], + }) +], OrdersModule); +//# sourceMappingURL=orders.module.js.map \ No newline at end of file diff --git a/dist/orders/orders.module.js.map b/dist/orders/orders.module.js.map new file mode 100644 index 0000000..9007052 --- /dev/null +++ b/dist/orders/orders.module.js.map @@ -0,0 +1 @@ +{"version":3,"file":"orders.module.js","sourceRoot":"","sources":["../../src/orders/orders.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,2DAG6B;AAC7B,qDAAiD;AAO1C,IAAM,YAAY,GAAlB,MAAM,YAAY;CAAG,CAAA;AAAf,oCAAY;uBAAZ,YAAY;IALxB,IAAA,eAAM,EAAC;QACN,WAAW,EAAE,CAAC,4CAAwB,EAAE,yCAAqB,CAAC;QAC9D,SAAS,EAAE,CAAC,8BAAa,CAAC;QAC1B,OAAO,EAAE,CAAC,8BAAa,CAAC;KACzB,CAAC;GACW,YAAY,CAAG"} \ No newline at end of file diff --git a/dist/orders/orders.service.d.ts b/dist/orders/orders.service.d.ts new file mode 100644 index 0000000..42849e0 --- /dev/null +++ b/dist/orders/orders.service.d.ts @@ -0,0 +1,1044 @@ +import { Prisma } from '@prisma/client'; +import { PrismaService } from '../prisma/prisma.service'; +import { AdminCreateOrderDto, SubmitOrderDto, UpdateOrderChecksDto, UpdateOrderPricingDto, UpdateOrderStatusDto } from './dto/order.dto'; +declare const orderInclude: { + items: true; + checks: { + orderBy: { + row: "asc"; + }; + }; + cashReceipt: true; + statusHistory: { + orderBy: { + changedAt: "asc"; + }; + }; + shipment: true; + user: true; + company: true; +}; +type OrderFull = Prisma.OrderGetPayload<{ + include: typeof orderInclude; +}>; +export declare class OrdersService { + private readonly prisma; + constructor(prisma: PrismaService); + findMyOrders(userId: string): Promise<{ + id: string; + orderNumber: string; + userId: string; + companyId: string; + companyName: string; + settlementType: import("@prisma/client").$Enums.SettlementType; + settlementMethod: import("@prisma/client").$Enums.SettlementType; + checkMode: import("@prisma/client").$Enums.CheckRegistrationMode | undefined; + status: import("@prisma/client").$Enums.OrderStatus; + adminStatus: string; + totalMeterage: number; + meterage: number; + totalAmount: number | null; + shippingCost: number | null; + totalDiscount: number | null; + finalAmount: number | null; + notes: string | undefined; + checkRassDays: number | undefined; + checkRassDate: string | undefined; + cashInvoiceExpiresAt: string | undefined; + createdAt: string; + updatedAt: string; + customerName: string; + customerPhone: string; + customerNationalId: string | undefined; + customerType: import("@prisma/client").$Enums.CustomerType; + items: { + id: string; + productId: string | undefined; + catalogCode: string; + productName: string; + productCode: string | undefined; + color: string; + requestedMeterage: number; + confirmedMeterage: number | null; + unitPrice: number | null; + supplyPrice: number | null; + unitDiscount: number; + discount: number; + lineTotal: number | null; + totalAmount: number | null; + notes: string | undefined; + }[]; + checks: { + id: string; + orderId: string; + row: number; + amount: number; + dueDate: string; + sayadId: string | undefined; + checkNumber: string | undefined; + ownerNationalId: string | undefined; + ownerFirstName: string | undefined; + ownerLastName: string | undefined; + bankName: string; + branchName: string | undefined; + frontImage: string | undefined; + backImage: string | undefined; + notes: string | undefined; + mode: import("@prisma/client").$Enums.CheckRegistrationMode; + status: import("@prisma/client").$Enums.CheckStatus; + createdAt: string; + updatedAt: string; + }[]; + cashReceipt: { + id: string; + amount: number; + paidAmount: number | null; + transferDate: string | null; + transferTime: string | undefined; + trackingNumber: string | undefined; + trackingCode: string | undefined; + destinationAccountId: string | undefined; + receiptImage: string | undefined; + notes: string | undefined; + expiresAt: string | undefined; + status: import("@prisma/client").$Enums.CashPaymentStatus; + submittedAt: string | undefined; + createdAt: string; + } | undefined; + shipment: { + id: string; + orderId: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + } | undefined; + statusHistory: { + id: string; + fromStatus: import("@prisma/client").$Enums.OrderStatus | null; + toStatus: import("@prisma/client").$Enums.OrderStatus; + changedBy: string; + note: string | undefined; + reason: string | undefined; + changedAt: string; + }[]; + }[]>; + findMyOrder(userId: string, id: string): Promise<{ + id: string; + orderNumber: string; + userId: string; + companyId: string; + companyName: string; + settlementType: import("@prisma/client").$Enums.SettlementType; + settlementMethod: import("@prisma/client").$Enums.SettlementType; + checkMode: import("@prisma/client").$Enums.CheckRegistrationMode | undefined; + status: import("@prisma/client").$Enums.OrderStatus; + adminStatus: string; + totalMeterage: number; + meterage: number; + totalAmount: number | null; + shippingCost: number | null; + totalDiscount: number | null; + finalAmount: number | null; + notes: string | undefined; + checkRassDays: number | undefined; + checkRassDate: string | undefined; + cashInvoiceExpiresAt: string | undefined; + createdAt: string; + updatedAt: string; + customerName: string; + customerPhone: string; + customerNationalId: string | undefined; + customerType: import("@prisma/client").$Enums.CustomerType; + items: { + id: string; + productId: string | undefined; + catalogCode: string; + productName: string; + productCode: string | undefined; + color: string; + requestedMeterage: number; + confirmedMeterage: number | null; + unitPrice: number | null; + supplyPrice: number | null; + unitDiscount: number; + discount: number; + lineTotal: number | null; + totalAmount: number | null; + notes: string | undefined; + }[]; + checks: { + id: string; + orderId: string; + row: number; + amount: number; + dueDate: string; + sayadId: string | undefined; + checkNumber: string | undefined; + ownerNationalId: string | undefined; + ownerFirstName: string | undefined; + ownerLastName: string | undefined; + bankName: string; + branchName: string | undefined; + frontImage: string | undefined; + backImage: string | undefined; + notes: string | undefined; + mode: import("@prisma/client").$Enums.CheckRegistrationMode; + status: import("@prisma/client").$Enums.CheckStatus; + createdAt: string; + updatedAt: string; + }[]; + cashReceipt: { + id: string; + amount: number; + paidAmount: number | null; + transferDate: string | null; + transferTime: string | undefined; + trackingNumber: string | undefined; + trackingCode: string | undefined; + destinationAccountId: string | undefined; + receiptImage: string | undefined; + notes: string | undefined; + expiresAt: string | undefined; + status: import("@prisma/client").$Enums.CashPaymentStatus; + submittedAt: string | undefined; + createdAt: string; + } | undefined; + shipment: { + id: string; + orderId: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + } | undefined; + statusHistory: { + id: string; + fromStatus: import("@prisma/client").$Enums.OrderStatus | null; + toStatus: import("@prisma/client").$Enums.OrderStatus; + changedBy: string; + note: string | undefined; + reason: string | undefined; + changedAt: string; + }[]; + }>; + findAdminOrders(filters: { + status?: string; + q?: string; + }): Promise<{ + id: string; + orderNumber: string; + userId: string; + companyId: string; + companyName: string; + settlementType: import("@prisma/client").$Enums.SettlementType; + settlementMethod: import("@prisma/client").$Enums.SettlementType; + checkMode: import("@prisma/client").$Enums.CheckRegistrationMode | undefined; + status: import("@prisma/client").$Enums.OrderStatus; + adminStatus: string; + totalMeterage: number; + meterage: number; + totalAmount: number | null; + shippingCost: number | null; + totalDiscount: number | null; + finalAmount: number | null; + notes: string | undefined; + checkRassDays: number | undefined; + checkRassDate: string | undefined; + cashInvoiceExpiresAt: string | undefined; + createdAt: string; + updatedAt: string; + customerName: string; + customerPhone: string; + customerNationalId: string | undefined; + customerType: import("@prisma/client").$Enums.CustomerType; + items: { + id: string; + productId: string | undefined; + catalogCode: string; + productName: string; + productCode: string | undefined; + color: string; + requestedMeterage: number; + confirmedMeterage: number | null; + unitPrice: number | null; + supplyPrice: number | null; + unitDiscount: number; + discount: number; + lineTotal: number | null; + totalAmount: number | null; + notes: string | undefined; + }[]; + checks: { + id: string; + orderId: string; + row: number; + amount: number; + dueDate: string; + sayadId: string | undefined; + checkNumber: string | undefined; + ownerNationalId: string | undefined; + ownerFirstName: string | undefined; + ownerLastName: string | undefined; + bankName: string; + branchName: string | undefined; + frontImage: string | undefined; + backImage: string | undefined; + notes: string | undefined; + mode: import("@prisma/client").$Enums.CheckRegistrationMode; + status: import("@prisma/client").$Enums.CheckStatus; + createdAt: string; + updatedAt: string; + }[]; + cashReceipt: { + id: string; + amount: number; + paidAmount: number | null; + transferDate: string | null; + transferTime: string | undefined; + trackingNumber: string | undefined; + trackingCode: string | undefined; + destinationAccountId: string | undefined; + receiptImage: string | undefined; + notes: string | undefined; + expiresAt: string | undefined; + status: import("@prisma/client").$Enums.CashPaymentStatus; + submittedAt: string | undefined; + createdAt: string; + } | undefined; + shipment: { + id: string; + orderId: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + } | undefined; + statusHistory: { + id: string; + fromStatus: import("@prisma/client").$Enums.OrderStatus | null; + toStatus: import("@prisma/client").$Enums.OrderStatus; + changedBy: string; + note: string | undefined; + reason: string | undefined; + changedAt: string; + }[]; + }[]>; + findAdminOrder(id: string): Promise<{ + id: string; + orderNumber: string; + userId: string; + companyId: string; + companyName: string; + settlementType: import("@prisma/client").$Enums.SettlementType; + settlementMethod: import("@prisma/client").$Enums.SettlementType; + checkMode: import("@prisma/client").$Enums.CheckRegistrationMode | undefined; + status: import("@prisma/client").$Enums.OrderStatus; + adminStatus: string; + totalMeterage: number; + meterage: number; + totalAmount: number | null; + shippingCost: number | null; + totalDiscount: number | null; + finalAmount: number | null; + notes: string | undefined; + checkRassDays: number | undefined; + checkRassDate: string | undefined; + cashInvoiceExpiresAt: string | undefined; + createdAt: string; + updatedAt: string; + customerName: string; + customerPhone: string; + customerNationalId: string | undefined; + customerType: import("@prisma/client").$Enums.CustomerType; + items: { + id: string; + productId: string | undefined; + catalogCode: string; + productName: string; + productCode: string | undefined; + color: string; + requestedMeterage: number; + confirmedMeterage: number | null; + unitPrice: number | null; + supplyPrice: number | null; + unitDiscount: number; + discount: number; + lineTotal: number | null; + totalAmount: number | null; + notes: string | undefined; + }[]; + checks: { + id: string; + orderId: string; + row: number; + amount: number; + dueDate: string; + sayadId: string | undefined; + checkNumber: string | undefined; + ownerNationalId: string | undefined; + ownerFirstName: string | undefined; + ownerLastName: string | undefined; + bankName: string; + branchName: string | undefined; + frontImage: string | undefined; + backImage: string | undefined; + notes: string | undefined; + mode: import("@prisma/client").$Enums.CheckRegistrationMode; + status: import("@prisma/client").$Enums.CheckStatus; + createdAt: string; + updatedAt: string; + }[]; + cashReceipt: { + id: string; + amount: number; + paidAmount: number | null; + transferDate: string | null; + transferTime: string | undefined; + trackingNumber: string | undefined; + trackingCode: string | undefined; + destinationAccountId: string | undefined; + receiptImage: string | undefined; + notes: string | undefined; + expiresAt: string | undefined; + status: import("@prisma/client").$Enums.CashPaymentStatus; + submittedAt: string | undefined; + createdAt: string; + } | undefined; + shipment: { + id: string; + orderId: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + } | undefined; + statusHistory: { + id: string; + fromStatus: import("@prisma/client").$Enums.OrderStatus | null; + toStatus: import("@prisma/client").$Enums.OrderStatus; + changedBy: string; + note: string | undefined; + reason: string | undefined; + changedAt: string; + }[]; + }>; + submitOrder(userId: string, dto: SubmitOrderDto): Promise<{ + id: string; + orderNumber: string; + userId: string; + companyId: string; + companyName: string; + settlementType: import("@prisma/client").$Enums.SettlementType; + settlementMethod: import("@prisma/client").$Enums.SettlementType; + checkMode: import("@prisma/client").$Enums.CheckRegistrationMode | undefined; + status: import("@prisma/client").$Enums.OrderStatus; + adminStatus: string; + totalMeterage: number; + meterage: number; + totalAmount: number | null; + shippingCost: number | null; + totalDiscount: number | null; + finalAmount: number | null; + notes: string | undefined; + checkRassDays: number | undefined; + checkRassDate: string | undefined; + cashInvoiceExpiresAt: string | undefined; + createdAt: string; + updatedAt: string; + customerName: string; + customerPhone: string; + customerNationalId: string | undefined; + customerType: import("@prisma/client").$Enums.CustomerType; + items: { + id: string; + productId: string | undefined; + catalogCode: string; + productName: string; + productCode: string | undefined; + color: string; + requestedMeterage: number; + confirmedMeterage: number | null; + unitPrice: number | null; + supplyPrice: number | null; + unitDiscount: number; + discount: number; + lineTotal: number | null; + totalAmount: number | null; + notes: string | undefined; + }[]; + checks: { + id: string; + orderId: string; + row: number; + amount: number; + dueDate: string; + sayadId: string | undefined; + checkNumber: string | undefined; + ownerNationalId: string | undefined; + ownerFirstName: string | undefined; + ownerLastName: string | undefined; + bankName: string; + branchName: string | undefined; + frontImage: string | undefined; + backImage: string | undefined; + notes: string | undefined; + mode: import("@prisma/client").$Enums.CheckRegistrationMode; + status: import("@prisma/client").$Enums.CheckStatus; + createdAt: string; + updatedAt: string; + }[]; + cashReceipt: { + id: string; + amount: number; + paidAmount: number | null; + transferDate: string | null; + transferTime: string | undefined; + trackingNumber: string | undefined; + trackingCode: string | undefined; + destinationAccountId: string | undefined; + receiptImage: string | undefined; + notes: string | undefined; + expiresAt: string | undefined; + status: import("@prisma/client").$Enums.CashPaymentStatus; + submittedAt: string | undefined; + createdAt: string; + } | undefined; + shipment: { + id: string; + orderId: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + } | undefined; + statusHistory: { + id: string; + fromStatus: import("@prisma/client").$Enums.OrderStatus | null; + toStatus: import("@prisma/client").$Enums.OrderStatus; + changedBy: string; + note: string | undefined; + reason: string | undefined; + changedAt: string; + }[]; + }>; + adminCreate(adminId: string, dto: AdminCreateOrderDto): Promise<{ + id: string; + orderNumber: string; + userId: string; + companyId: string; + companyName: string; + settlementType: import("@prisma/client").$Enums.SettlementType; + settlementMethod: import("@prisma/client").$Enums.SettlementType; + checkMode: import("@prisma/client").$Enums.CheckRegistrationMode | undefined; + status: import("@prisma/client").$Enums.OrderStatus; + adminStatus: string; + totalMeterage: number; + meterage: number; + totalAmount: number | null; + shippingCost: number | null; + totalDiscount: number | null; + finalAmount: number | null; + notes: string | undefined; + checkRassDays: number | undefined; + checkRassDate: string | undefined; + cashInvoiceExpiresAt: string | undefined; + createdAt: string; + updatedAt: string; + customerName: string; + customerPhone: string; + customerNationalId: string | undefined; + customerType: import("@prisma/client").$Enums.CustomerType; + items: { + id: string; + productId: string | undefined; + catalogCode: string; + productName: string; + productCode: string | undefined; + color: string; + requestedMeterage: number; + confirmedMeterage: number | null; + unitPrice: number | null; + supplyPrice: number | null; + unitDiscount: number; + discount: number; + lineTotal: number | null; + totalAmount: number | null; + notes: string | undefined; + }[]; + checks: { + id: string; + orderId: string; + row: number; + amount: number; + dueDate: string; + sayadId: string | undefined; + checkNumber: string | undefined; + ownerNationalId: string | undefined; + ownerFirstName: string | undefined; + ownerLastName: string | undefined; + bankName: string; + branchName: string | undefined; + frontImage: string | undefined; + backImage: string | undefined; + notes: string | undefined; + mode: import("@prisma/client").$Enums.CheckRegistrationMode; + status: import("@prisma/client").$Enums.CheckStatus; + createdAt: string; + updatedAt: string; + }[]; + cashReceipt: { + id: string; + amount: number; + paidAmount: number | null; + transferDate: string | null; + transferTime: string | undefined; + trackingNumber: string | undefined; + trackingCode: string | undefined; + destinationAccountId: string | undefined; + receiptImage: string | undefined; + notes: string | undefined; + expiresAt: string | undefined; + status: import("@prisma/client").$Enums.CashPaymentStatus; + submittedAt: string | undefined; + createdAt: string; + } | undefined; + shipment: { + id: string; + orderId: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + } | undefined; + statusHistory: { + id: string; + fromStatus: import("@prisma/client").$Enums.OrderStatus | null; + toStatus: import("@prisma/client").$Enums.OrderStatus; + changedBy: string; + note: string | undefined; + reason: string | undefined; + changedAt: string; + }[]; + }>; + updatePricing(id: string, adminId: string, dto: UpdateOrderPricingDto): Promise<{ + id: string; + orderNumber: string; + userId: string; + companyId: string; + companyName: string; + settlementType: import("@prisma/client").$Enums.SettlementType; + settlementMethod: import("@prisma/client").$Enums.SettlementType; + checkMode: import("@prisma/client").$Enums.CheckRegistrationMode | undefined; + status: import("@prisma/client").$Enums.OrderStatus; + adminStatus: string; + totalMeterage: number; + meterage: number; + totalAmount: number | null; + shippingCost: number | null; + totalDiscount: number | null; + finalAmount: number | null; + notes: string | undefined; + checkRassDays: number | undefined; + checkRassDate: string | undefined; + cashInvoiceExpiresAt: string | undefined; + createdAt: string; + updatedAt: string; + customerName: string; + customerPhone: string; + customerNationalId: string | undefined; + customerType: import("@prisma/client").$Enums.CustomerType; + items: { + id: string; + productId: string | undefined; + catalogCode: string; + productName: string; + productCode: string | undefined; + color: string; + requestedMeterage: number; + confirmedMeterage: number | null; + unitPrice: number | null; + supplyPrice: number | null; + unitDiscount: number; + discount: number; + lineTotal: number | null; + totalAmount: number | null; + notes: string | undefined; + }[]; + checks: { + id: string; + orderId: string; + row: number; + amount: number; + dueDate: string; + sayadId: string | undefined; + checkNumber: string | undefined; + ownerNationalId: string | undefined; + ownerFirstName: string | undefined; + ownerLastName: string | undefined; + bankName: string; + branchName: string | undefined; + frontImage: string | undefined; + backImage: string | undefined; + notes: string | undefined; + mode: import("@prisma/client").$Enums.CheckRegistrationMode; + status: import("@prisma/client").$Enums.CheckStatus; + createdAt: string; + updatedAt: string; + }[]; + cashReceipt: { + id: string; + amount: number; + paidAmount: number | null; + transferDate: string | null; + transferTime: string | undefined; + trackingNumber: string | undefined; + trackingCode: string | undefined; + destinationAccountId: string | undefined; + receiptImage: string | undefined; + notes: string | undefined; + expiresAt: string | undefined; + status: import("@prisma/client").$Enums.CashPaymentStatus; + submittedAt: string | undefined; + createdAt: string; + } | undefined; + shipment: { + id: string; + orderId: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + } | undefined; + statusHistory: { + id: string; + fromStatus: import("@prisma/client").$Enums.OrderStatus | null; + toStatus: import("@prisma/client").$Enums.OrderStatus; + changedBy: string; + note: string | undefined; + reason: string | undefined; + changedAt: string; + }[]; + }>; + updateStatus(id: string, adminId: string, dto: UpdateOrderStatusDto): Promise<{ + id: string; + orderNumber: string; + userId: string; + companyId: string; + companyName: string; + settlementType: import("@prisma/client").$Enums.SettlementType; + settlementMethod: import("@prisma/client").$Enums.SettlementType; + checkMode: import("@prisma/client").$Enums.CheckRegistrationMode | undefined; + status: import("@prisma/client").$Enums.OrderStatus; + adminStatus: string; + totalMeterage: number; + meterage: number; + totalAmount: number | null; + shippingCost: number | null; + totalDiscount: number | null; + finalAmount: number | null; + notes: string | undefined; + checkRassDays: number | undefined; + checkRassDate: string | undefined; + cashInvoiceExpiresAt: string | undefined; + createdAt: string; + updatedAt: string; + customerName: string; + customerPhone: string; + customerNationalId: string | undefined; + customerType: import("@prisma/client").$Enums.CustomerType; + items: { + id: string; + productId: string | undefined; + catalogCode: string; + productName: string; + productCode: string | undefined; + color: string; + requestedMeterage: number; + confirmedMeterage: number | null; + unitPrice: number | null; + supplyPrice: number | null; + unitDiscount: number; + discount: number; + lineTotal: number | null; + totalAmount: number | null; + notes: string | undefined; + }[]; + checks: { + id: string; + orderId: string; + row: number; + amount: number; + dueDate: string; + sayadId: string | undefined; + checkNumber: string | undefined; + ownerNationalId: string | undefined; + ownerFirstName: string | undefined; + ownerLastName: string | undefined; + bankName: string; + branchName: string | undefined; + frontImage: string | undefined; + backImage: string | undefined; + notes: string | undefined; + mode: import("@prisma/client").$Enums.CheckRegistrationMode; + status: import("@prisma/client").$Enums.CheckStatus; + createdAt: string; + updatedAt: string; + }[]; + cashReceipt: { + id: string; + amount: number; + paidAmount: number | null; + transferDate: string | null; + transferTime: string | undefined; + trackingNumber: string | undefined; + trackingCode: string | undefined; + destinationAccountId: string | undefined; + receiptImage: string | undefined; + notes: string | undefined; + expiresAt: string | undefined; + status: import("@prisma/client").$Enums.CashPaymentStatus; + submittedAt: string | undefined; + createdAt: string; + } | undefined; + shipment: { + id: string; + orderId: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + } | undefined; + statusHistory: { + id: string; + fromStatus: import("@prisma/client").$Enums.OrderStatus | null; + toStatus: import("@prisma/client").$Enums.OrderStatus; + changedBy: string; + note: string | undefined; + reason: string | undefined; + changedAt: string; + }[]; + }>; + updateChecks(userId: string, id: string, dto: UpdateOrderChecksDto): Promise<{ + id: string; + orderNumber: string; + userId: string; + companyId: string; + companyName: string; + settlementType: import("@prisma/client").$Enums.SettlementType; + settlementMethod: import("@prisma/client").$Enums.SettlementType; + checkMode: import("@prisma/client").$Enums.CheckRegistrationMode | undefined; + status: import("@prisma/client").$Enums.OrderStatus; + adminStatus: string; + totalMeterage: number; + meterage: number; + totalAmount: number | null; + shippingCost: number | null; + totalDiscount: number | null; + finalAmount: number | null; + notes: string | undefined; + checkRassDays: number | undefined; + checkRassDate: string | undefined; + cashInvoiceExpiresAt: string | undefined; + createdAt: string; + updatedAt: string; + customerName: string; + customerPhone: string; + customerNationalId: string | undefined; + customerType: import("@prisma/client").$Enums.CustomerType; + items: { + id: string; + productId: string | undefined; + catalogCode: string; + productName: string; + productCode: string | undefined; + color: string; + requestedMeterage: number; + confirmedMeterage: number | null; + unitPrice: number | null; + supplyPrice: number | null; + unitDiscount: number; + discount: number; + lineTotal: number | null; + totalAmount: number | null; + notes: string | undefined; + }[]; + checks: { + id: string; + orderId: string; + row: number; + amount: number; + dueDate: string; + sayadId: string | undefined; + checkNumber: string | undefined; + ownerNationalId: string | undefined; + ownerFirstName: string | undefined; + ownerLastName: string | undefined; + bankName: string; + branchName: string | undefined; + frontImage: string | undefined; + backImage: string | undefined; + notes: string | undefined; + mode: import("@prisma/client").$Enums.CheckRegistrationMode; + status: import("@prisma/client").$Enums.CheckStatus; + createdAt: string; + updatedAt: string; + }[]; + cashReceipt: { + id: string; + amount: number; + paidAmount: number | null; + transferDate: string | null; + transferTime: string | undefined; + trackingNumber: string | undefined; + trackingCode: string | undefined; + destinationAccountId: string | undefined; + receiptImage: string | undefined; + notes: string | undefined; + expiresAt: string | undefined; + status: import("@prisma/client").$Enums.CashPaymentStatus; + submittedAt: string | undefined; + createdAt: string; + } | undefined; + shipment: { + id: string; + orderId: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + } | undefined; + statusHistory: { + id: string; + fromStatus: import("@prisma/client").$Enums.OrderStatus | null; + toStatus: import("@prisma/client").$Enums.OrderStatus; + changedBy: string; + note: string | undefined; + reason: string | undefined; + changedAt: string; + }[]; + }>; + private mapCheckCreate; + private nextOrderNumber; + private getOrder; + mapOrder(order: OrderFull, adminView?: boolean): { + id: string; + orderNumber: string; + userId: string; + companyId: string; + companyName: string; + settlementType: import("@prisma/client").$Enums.SettlementType; + settlementMethod: import("@prisma/client").$Enums.SettlementType; + checkMode: import("@prisma/client").$Enums.CheckRegistrationMode | undefined; + status: import("@prisma/client").$Enums.OrderStatus; + adminStatus: string; + totalMeterage: number; + meterage: number; + totalAmount: number | null; + shippingCost: number | null; + totalDiscount: number | null; + finalAmount: number | null; + notes: string | undefined; + checkRassDays: number | undefined; + checkRassDate: string | undefined; + cashInvoiceExpiresAt: string | undefined; + createdAt: string; + updatedAt: string; + customerName: string; + customerPhone: string; + customerNationalId: string | undefined; + customerType: import("@prisma/client").$Enums.CustomerType; + items: { + id: string; + productId: string | undefined; + catalogCode: string; + productName: string; + productCode: string | undefined; + color: string; + requestedMeterage: number; + confirmedMeterage: number | null; + unitPrice: number | null; + supplyPrice: number | null; + unitDiscount: number; + discount: number; + lineTotal: number | null; + totalAmount: number | null; + notes: string | undefined; + }[]; + checks: { + id: string; + orderId: string; + row: number; + amount: number; + dueDate: string; + sayadId: string | undefined; + checkNumber: string | undefined; + ownerNationalId: string | undefined; + ownerFirstName: string | undefined; + ownerLastName: string | undefined; + bankName: string; + branchName: string | undefined; + frontImage: string | undefined; + backImage: string | undefined; + notes: string | undefined; + mode: import("@prisma/client").$Enums.CheckRegistrationMode; + status: import("@prisma/client").$Enums.CheckStatus; + createdAt: string; + updatedAt: string; + }[]; + cashReceipt: { + id: string; + amount: number; + paidAmount: number | null; + transferDate: string | null; + transferTime: string | undefined; + trackingNumber: string | undefined; + trackingCode: string | undefined; + destinationAccountId: string | undefined; + receiptImage: string | undefined; + notes: string | undefined; + expiresAt: string | undefined; + status: import("@prisma/client").$Enums.CashPaymentStatus; + submittedAt: string | undefined; + createdAt: string; + } | undefined; + shipment: { + id: string; + orderId: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + } | undefined; + statusHistory: { + id: string; + fromStatus: import("@prisma/client").$Enums.OrderStatus | null; + toStatus: import("@prisma/client").$Enums.OrderStatus; + changedBy: string; + note: string | undefined; + reason: string | undefined; + changedAt: string; + }[]; + }; +} +export {}; diff --git a/dist/orders/orders.service.js b/dist/orders/orders.service.js new file mode 100644 index 0000000..984801f --- /dev/null +++ b/dist/orders/orders.service.js @@ -0,0 +1,549 @@ +"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.OrdersService = void 0; +const common_1 = require("@nestjs/common"); +const client_1 = require("@prisma/client"); +const prisma_service_1 = require("../prisma/prisma.service"); +const order_number_1 = require("../common/utils/order-number"); +const check_rass_1 = require("../common/utils/check-rass"); +const cash_expiry_1 = require("../common/utils/cash-expiry"); +const order_status_1 = require("../common/utils/order-status"); +const name_1 = require("../common/utils/name"); +const phone_1 = require("../common/utils/phone"); +const orderInclude = { + items: true, + checks: { orderBy: { row: 'asc' } }, + cashReceipt: true, + statusHistory: { orderBy: { changedAt: 'asc' } }, + shipment: true, + user: true, + company: true, +}; +let OrdersService = class OrdersService { + prisma; + constructor(prisma) { + this.prisma = prisma; + } + async findMyOrders(userId) { + const orders = await this.prisma.order.findMany({ + where: { userId }, + orderBy: { createdAt: 'desc' }, + include: orderInclude, + }); + return orders.map((o) => this.mapOrder(o)); + } + async findMyOrder(userId, id) { + const order = await this.getOrder(id); + if (order.userId !== userId) { + throw new common_1.ForbiddenException('دسترسی به این سفارش مجاز نیست'); + } + return this.mapOrder(order); + } + async findAdminOrders(filters) { + const statuses = (0, order_status_1.resolveAdminStatusFilter)(filters.status); + const q = filters.q?.trim(); + const orders = await this.prisma.order.findMany({ + where: { + ...(statuses ? { status: { in: statuses } } : {}), + ...(q + ? { + OR: [ + { orderNumber: { contains: q, mode: 'insensitive' } }, + { companyName: { contains: q, mode: 'insensitive' } }, + { + user: { + OR: [ + { firstName: { contains: q, mode: 'insensitive' } }, + { lastName: { contains: q, mode: 'insensitive' } }, + { phone: { contains: (0, phone_1.toEnglishDigits)(q) } }, + ], + }, + }, + ], + } + : {}), + }, + orderBy: { createdAt: 'desc' }, + include: orderInclude, + }); + return orders.map((o) => this.mapOrder(o, true)); + } + async findAdminOrder(id) { + const order = await this.getOrder(id); + return this.mapOrder(order, true); + } + async submitOrder(userId, dto) { + const company = await this.prisma.company.findUnique({ + where: { id: dto.companyId }, + }); + if (!company || !company.isActive) { + throw new common_1.NotFoundException('شرکت یافت نشد یا غیرفعال است'); + } + const productIds = dto.items.map((i) => i.productId); + const products = await this.prisma.product.findMany({ + where: { id: { in: productIds }, companyId: company.id, isActive: true }, + include: { catalog: true }, + }); + if (products.length !== productIds.length) { + throw new common_1.BadRequestException('یک یا چند محصول نامعتبر است'); + } + const productMap = new Map(products.map((p) => [p.id, p])); + let totalMeterage = 0; + const itemsData = dto.items.map((item) => { + const product = productMap.get(item.productId); + if (item.meterage < product.minMeterage) { + throw new common_1.BadRequestException(`حداقل متراژ برای ${product.name} برابر ${product.minMeterage} است`); + } + const rem = Math.round((item.meterage / product.orderMultiplier) * 1000) / 1000; + if (Math.abs(rem - Math.round(rem)) > 1e-6) { + throw new common_1.BadRequestException(`متراژ ${product.name} باید مضرب ${product.orderMultiplier} باشد`); + } + totalMeterage += item.meterage; + return { + productId: product.id, + catalogCode: product.catalog.code, + productName: product.name, + productCode: product.code, + color: product.color, + requestedMeterage: item.meterage, + unitPrice: product.basePrice, + notes: item.notes?.trim() || null, + }; + }); + if (totalMeterage > company.maxMeteragePerInvoice) { + throw new common_1.BadRequestException(`حداکثر متراژ مجاز هر فاکتور ${company.maxMeteragePerInvoice} متر است`); + } + const settlementType = dto.settlementType; + if (settlementType === client_1.SettlementType.check) { + if (!dto.checks?.length) { + throw new common_1.BadRequestException('برای تسویه چکی حداقل یک چک لازم است'); + } + } + const checkMode = settlementType === client_1.SettlementType.check + ? (dto.checkMode ?? client_1.CheckRegistrationMode.full) + : null; + const rass = settlementType === client_1.SettlementType.check && dto.checks?.length + ? (0, check_rass_1.calculateCheckRass)(dto.checks.map((c) => ({ + amount: c.amount, + dueDate: c.dueDate, + }))) + : null; + const cashInvoiceExpiresAt = settlementType === client_1.SettlementType.cash + ? (0, cash_expiry_1.computeCashInvoiceExpiry)(company) + : null; + const orderNumber = await this.nextOrderNumber(); + const order = await this.prisma.$transaction(async (tx) => { + const created = await tx.order.create({ + data: { + orderNumber, + userId, + companyId: company.id, + companyName: company.name, + settlementType, + checkMode, + status: client_1.OrderStatus.awaiting_review, + totalMeterage, + notes: dto.notes?.trim() || null, + checkRassDays: rass?.rassDays ?? null, + checkRassDate: rass?.rassDate ? new Date(rass.rassDate) : null, + cashInvoiceExpiresAt, + items: { create: itemsData }, + checks: settlementType === client_1.SettlementType.check && dto.checks + ? { + create: dto.checks.map((c, index) => this.mapCheckCreate(c, index + 1, checkMode)), + } + : undefined, + statusHistory: { + create: [ + { + fromStatus: null, + toStatus: client_1.OrderStatus.submitted, + changedBy: 'customer', + note: 'سفارش ثبت شد', + }, + { + fromStatus: client_1.OrderStatus.submitted, + toStatus: client_1.OrderStatus.awaiting_review, + changedBy: 'customer', + note: 'ارسال برای بررسی مدیریت', + }, + ], + }, + }, + include: orderInclude, + }); + const cart = await tx.cart.findFirst({ where: { userId } }); + if (cart) { + await tx.cartItem.deleteMany({ + where: { cartId: cart.id, companyId: company.id }, + }); + } + return created; + }); + return this.mapOrder(order); + } + async adminCreate(adminId, dto) { + const settlementType = dto.settlementType ?? dto.settlementMethod; + if (!settlementType) { + throw new common_1.BadRequestException('نوع تسویه الزامی است'); + } + const company = await this.prisma.company.findUnique({ + where: { id: dto.companyId }, + }); + if (!company) + throw new common_1.NotFoundException('شرکت یافت نشد'); + let userId = dto.userId; + if (!userId && dto.customerPhone) { + const phone = (0, phone_1.normalizePhone)((0, phone_1.toEnglishDigits)(dto.customerPhone)); + if (!(0, phone_1.isValidPhone)(phone)) { + throw new common_1.BadRequestException('شماره موبایل نامعتبر است'); + } + let customer = await this.prisma.customer.findUnique({ where: { phone } }); + if (!customer) { + const names = (0, name_1.splitFullName)(dto.customerName || 'مشتری جدید'); + customer = await this.prisma.customer.create({ + data: { + phone, + firstName: names.firstName, + lastName: names.lastName || 'جدید', + }, + }); + } + userId = customer.id; + } + if (!userId) { + throw new common_1.BadRequestException('شناسه یا شماره مشتری الزامی است'); + } + const orderNumber = await this.nextOrderNumber(); + const totalMeterage = dto.meterage ?? 0; + const order = await this.prisma.order.create({ + data: { + orderNumber, + userId, + companyId: company.id, + companyName: company.name, + settlementType, + status: client_1.OrderStatus.awaiting_review, + totalMeterage, + notes: dto.notes?.trim() || null, + statusHistory: { + create: { + fromStatus: null, + toStatus: client_1.OrderStatus.awaiting_review, + changedBy: `admin:${adminId}`, + note: 'سفارش توسط ادمین ثبت شد', + }, + }, + }, + include: orderInclude, + }); + return this.mapOrder(order, true); + } + async updatePricing(id, adminId, dto) { + const order = await this.getOrder(id); + await this.prisma.$transaction(async (tx) => { + let totalAmount = 0; + let totalMeterage = 0; + for (const item of dto.items) { + const existing = order.items.find((i) => i.id === item.id); + if (!existing) { + throw new common_1.BadRequestException(`آیتم ${item.id} یافت نشد`); + } + const unitPrice = item.unitPrice !== undefined + ? item.unitPrice + : item.supplyPrice !== undefined + ? item.supplyPrice + : (existing.unitPrice ?? 0); + const unitDiscount = item.unitDiscount ?? existing.unitDiscount ?? 0; + const confirmed = item.confirmedMeterage ?? + existing.confirmedMeterage ?? + existing.requestedMeterage; + const lineTotal = Math.max(0, (unitPrice - unitDiscount) * confirmed); + totalAmount += lineTotal; + totalMeterage += confirmed; + await tx.orderItem.update({ + where: { id: item.id }, + data: { + confirmedMeterage: confirmed, + unitPrice, + unitDiscount, + lineTotal, + }, + }); + } + const shippingCost = dto.shippingCost ?? order.shippingCost ?? 0; + const totalDiscount = dto.totalDiscount ?? order.totalDiscount ?? 0; + const finalAmount = Math.max(0, totalAmount + shippingCost - totalDiscount); + const nextStatus = order.status === client_1.OrderStatus.awaiting_review || + order.status === client_1.OrderStatus.pricing + ? client_1.OrderStatus.pricing + : order.status; + await tx.order.update({ + where: { id }, + data: { + totalAmount, + totalMeterage, + shippingCost, + totalDiscount, + finalAmount, + status: nextStatus, + }, + }); + if (nextStatus !== order.status) { + await tx.orderStatusHistory.create({ + data: { + orderId: id, + fromStatus: order.status, + toStatus: nextStatus, + changedBy: `admin:${adminId}`, + note: dto.note || 'قیمت‌گذاری انجام شد', + }, + }); + } + }); + return this.findAdminOrder(id); + } + async updateStatus(id, adminId, dto) { + const order = await this.getOrder(id); + if (order.status === dto.status) { + return this.mapOrder(order, true); + } + await this.prisma.$transaction(async (tx) => { + await tx.order.update({ + where: { id }, + data: { status: dto.status }, + }); + await tx.orderStatusHistory.create({ + data: { + orderId: id, + fromStatus: order.status, + toStatus: dto.status, + changedBy: `admin:${adminId}`, + note: dto.note || null, + reason: dto.reason || null, + }, + }); + if (dto.status === client_1.OrderStatus.cash_invoice_issued || + dto.status === client_1.OrderStatus.awaiting_cash_payment) { + if (!order.cashInvoiceExpiresAt) { + await tx.order.update({ + where: { id }, + data: { + cashInvoiceExpiresAt: (0, cash_expiry_1.computeCashInvoiceExpiry)(order.company), + }, + }); + } + } + }); + return this.findAdminOrder(id); + } + async updateChecks(userId, id, dto) { + const order = await this.getOrder(id); + if (order.userId !== userId) { + throw new common_1.ForbiddenException('دسترسی به این سفارش مجاز نیست'); + } + if (order.settlementType !== client_1.SettlementType.check) { + throw new common_1.BadRequestException('این سفارش تسویه چکی نیست'); + } + const checkMode = dto.checkMode ?? order.checkMode ?? client_1.CheckRegistrationMode.full; + const rass = (0, check_rass_1.calculateCheckRass)(dto.checks.map((c) => ({ amount: c.amount, dueDate: c.dueDate })), order.createdAt); + await this.prisma.$transaction(async (tx) => { + await tx.check.deleteMany({ where: { orderId: id } }); + await tx.check.createMany({ + data: dto.checks.map((c, index) => ({ + orderId: id, + ...this.mapCheckCreate(c, index + 1, checkMode), + })), + }); + await tx.order.update({ + where: { id }, + data: { + checkMode, + checkRassDays: rass.rassDays, + checkRassDate: rass.rassDate ? new Date(rass.rassDate) : null, + status: order.status === client_1.OrderStatus.check_needs_fix + ? client_1.OrderStatus.awaiting_check_review + : order.status, + }, + }); + if (order.status === client_1.OrderStatus.check_needs_fix) { + await tx.orderStatusHistory.create({ + data: { + orderId: id, + fromStatus: order.status, + toStatus: client_1.OrderStatus.awaiting_check_review, + changedBy: 'customer', + note: 'چک‌ها اصلاح و مجدداً ارسال شد', + }, + }); + } + }); + return this.findMyOrder(userId, id); + } + mapCheckCreate(c, row, defaultMode) { + return { + row, + amount: c.amount, + dueDate: new Date(c.dueDate), + sayadId: c.sayadId?.trim() || null, + checkNumber: c.checkNumber?.trim() || null, + ownerNationalId: c.ownerNationalId?.trim() || null, + ownerFirstName: c.ownerFirstName?.trim() || null, + ownerLastName: c.ownerLastName?.trim() || null, + bankName: c.bankName?.trim() || null, + branchName: c.branchName?.trim() || null, + frontImage: c.frontImage || null, + backImage: c.backImage || null, + notes: c.notes?.trim() || null, + mode: c.mode ?? defaultMode, + }; + } + async nextOrderNumber() { + for (let i = 0; i < 5; i++) { + const orderNumber = (0, order_number_1.generateOrderNumber)(); + const exists = await this.prisma.order.findUnique({ + where: { orderNumber }, + }); + if (!exists) + return orderNumber; + } + return `${(0, order_number_1.generateOrderNumber)()}-${Date.now().toString().slice(-3)}`; + } + async getOrder(id) { + const order = await this.prisma.order.findUnique({ + where: { id }, + include: orderInclude, + }); + if (!order) + throw new common_1.NotFoundException('سفارش یافت نشد'); + return order; + } + mapOrder(order, adminView = false) { + const customerName = (0, name_1.joinFullName)(order.user.firstName, order.user.lastName); + const base = { + id: order.id, + orderNumber: order.orderNumber, + userId: order.userId, + companyId: order.companyId, + companyName: order.companyName, + settlementType: order.settlementType, + settlementMethod: order.settlementType, + checkMode: order.checkMode ?? undefined, + status: order.status, + adminStatus: (0, order_status_1.toAdminStatus)(order.status), + totalMeterage: order.totalMeterage, + meterage: order.totalMeterage, + totalAmount: order.totalAmount, + shippingCost: order.shippingCost, + totalDiscount: order.totalDiscount, + finalAmount: order.finalAmount, + notes: order.notes ?? undefined, + checkRassDays: order.checkRassDays ?? undefined, + checkRassDate: order.checkRassDate?.toISOString(), + cashInvoiceExpiresAt: order.cashInvoiceExpiresAt?.toISOString(), + createdAt: order.createdAt.toISOString(), + updatedAt: order.updatedAt.toISOString(), + customerName, + customerPhone: order.user.phone, + customerNationalId: order.user.nationalId ?? undefined, + customerType: order.user.customerType, + items: order.items.map((item) => ({ + id: item.id, + productId: item.productId ?? undefined, + catalogCode: item.catalogCode, + productName: item.productName, + productCode: item.productCode ?? undefined, + color: item.color, + requestedMeterage: item.requestedMeterage, + confirmedMeterage: item.confirmedMeterage, + unitPrice: item.unitPrice, + supplyPrice: item.unitPrice, + unitDiscount: item.unitDiscount ?? 0, + discount: item.unitDiscount ?? 0, + lineTotal: item.lineTotal, + totalAmount: item.lineTotal, + notes: item.notes ?? undefined, + })), + checks: order.checks.map((c) => ({ + id: c.id, + orderId: c.orderId, + row: c.row, + amount: c.amount, + dueDate: c.dueDate.toISOString(), + sayadId: c.sayadId ?? undefined, + checkNumber: c.checkNumber ?? undefined, + ownerNationalId: c.ownerNationalId ?? undefined, + ownerFirstName: c.ownerFirstName ?? undefined, + ownerLastName: c.ownerLastName ?? undefined, + bankName: c.bankName ?? '', + branchName: c.branchName ?? undefined, + frontImage: c.frontImage ?? undefined, + backImage: c.backImage ?? undefined, + notes: c.notes ?? undefined, + mode: c.mode, + status: c.status, + createdAt: c.createdAt.toISOString(), + updatedAt: c.updatedAt.toISOString(), + })), + cashReceipt: order.cashReceipt + ? { + id: order.cashReceipt.id, + amount: order.cashReceipt.amount, + paidAmount: order.cashReceipt.paidAmount, + transferDate: order.cashReceipt.transferDate?.toISOString() ?? null, + transferTime: order.cashReceipt.transferTime ?? undefined, + trackingNumber: order.cashReceipt.trackingNumber ?? undefined, + trackingCode: order.cashReceipt.trackingNumber ?? undefined, + destinationAccountId: order.cashReceipt.destinationAccountId ?? undefined, + receiptImage: order.cashReceipt.receiptImage ?? undefined, + notes: order.cashReceipt.notes ?? undefined, + expiresAt: order.cashReceipt.expiresAt?.toISOString() ?? + order.cashInvoiceExpiresAt?.toISOString(), + status: order.cashReceipt.status, + submittedAt: order.cashReceipt.submittedAt?.toISOString(), + createdAt: order.cashReceipt.createdAt.toISOString(), + } + : undefined, + shipment: order.shipment + ? { + id: order.shipment.id, + orderId: order.shipment.orderId, + carrier: order.shipment.carrier, + trackingNumber: order.shipment.trackingNumber ?? '', + meterage: order.shipment.meterage, + status: order.shipment.status, + shippedAt: order.shipment.shippedAt?.toISOString() ?? null, + deliveredAt: order.shipment.deliveredAt?.toISOString() ?? null, + } + : undefined, + statusHistory: order.statusHistory.map((h) => ({ + id: h.id, + fromStatus: h.fromStatus, + toStatus: h.toStatus, + changedBy: h.changedBy, + note: h.note ?? undefined, + reason: h.reason ?? undefined, + changedAt: h.changedAt.toISOString(), + })), + }; + if (adminView) { + return base; + } + return base; + } +}; +exports.OrdersService = OrdersService; +exports.OrdersService = OrdersService = __decorate([ + (0, common_1.Injectable)(), + __metadata("design:paramtypes", [prisma_service_1.PrismaService]) +], OrdersService); +//# sourceMappingURL=orders.service.js.map \ No newline at end of file diff --git a/dist/orders/orders.service.js.map b/dist/orders/orders.service.js.map new file mode 100644 index 0000000..ebd650d --- /dev/null +++ b/dist/orders/orders.service.js.map @@ -0,0 +1 @@ +{"version":3,"file":"orders.service.js","sourceRoot":"","sources":["../../src/orders/orders.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAKwB;AACxB,2CAKwB;AACxB,6DAAyD;AASzD,+DAAmE;AACnE,2DAAgE;AAChE,6DAAuE;AACvE,+DAGsC;AACtC,+CAAmE;AACnE,iDAI+B;AAE/B,MAAM,YAAY,GAAG;IACnB,KAAK,EAAE,IAAI;IACX,MAAM,EAAE,EAAE,OAAO,EAAE,EAAE,G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,CAAC,UAAU;gBACxB,QAAQ,EAAE,CAAC,CAAC,QAAQ;gBACpB,SAAS,EAAE,CAAC,CAAC,SAAS;gBACtB,IAAI,EAAE,CAAC,CAAC,IAAI,IAAI,SAAS;gBACzB,MAAM,EAAE,CAAC,CAAC,MAAM,IAAI,SAAS;gBAC7B,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,WAAW,EAAE;aACrC,CAAC,CAAC;SACJ,CAAC;QAEF,IAAI,SAAS,EAAE,CAAC;YACd,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAllBY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;qCAE0B,8BAAa;GADvC,aAAa,CAklBzB"} \ No newline at end of file diff --git a/dist/prisma/prisma.module.d.ts b/dist/prisma/prisma.module.d.ts new file mode 100644 index 0000000..1cba5ae --- /dev/null +++ b/dist/prisma/prisma.module.d.ts @@ -0,0 +1,2 @@ +export declare class PrismaModule { +} diff --git a/dist/prisma/prisma.module.js b/dist/prisma/prisma.module.js new file mode 100644 index 0000000..d3729fa --- /dev/null +++ b/dist/prisma/prisma.module.js @@ -0,0 +1,22 @@ +"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.PrismaModule = void 0; +const common_1 = require("@nestjs/common"); +const prisma_service_1 = require("./prisma.service"); +let PrismaModule = class PrismaModule { +}; +exports.PrismaModule = PrismaModule; +exports.PrismaModule = PrismaModule = __decorate([ + (0, common_1.Global)(), + (0, common_1.Module)({ + providers: [prisma_service_1.PrismaService], + exports: [prisma_service_1.PrismaService], + }) +], PrismaModule); +//# sourceMappingURL=prisma.module.js.map \ No newline at end of file diff --git a/dist/prisma/prisma.module.js.map b/dist/prisma/prisma.module.js.map new file mode 100644 index 0000000..b1aba81 --- /dev/null +++ b/dist/prisma/prisma.module.js.map @@ -0,0 +1 @@ +{"version":3,"file":"prisma.module.js","sourceRoot":"","sources":["../../src/prisma/prisma.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAgD;AAChD,qDAAiD;AAO1C,IAAM,YAAY,GAAlB,MAAM,YAAY;CAAG,CAAA;AAAf,oCAAY;uBAAZ,YAAY;IALxB,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACN,SAAS,EAAE,CAAC,8BAAa,CAAC;QAC1B,OAAO,EAAE,CAAC,8BAAa,CAAC;KACzB,CAAC;GACW,YAAY,CAAG"} \ No newline at end of file diff --git a/dist/prisma/prisma.service.d.ts b/dist/prisma/prisma.service.d.ts new file mode 100644 index 0000000..3b94c78 --- /dev/null +++ b/dist/prisma/prisma.service.d.ts @@ -0,0 +1,6 @@ +import { OnModuleInit, OnModuleDestroy } from '@nestjs/common'; +import { PrismaClient } from '@prisma/client'; +export declare class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy { + onModuleInit(): Promise; + onModuleDestroy(): Promise; +} diff --git a/dist/prisma/prisma.service.js b/dist/prisma/prisma.service.js new file mode 100644 index 0000000..a5f7bec --- /dev/null +++ b/dist/prisma/prisma.service.js @@ -0,0 +1,24 @@ +"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.PrismaService = void 0; +const common_1 = require("@nestjs/common"); +const client_1 = require("@prisma/client"); +let PrismaService = class PrismaService extends client_1.PrismaClient { + async onModuleInit() { + await this.$connect(); + } + async onModuleDestroy() { + await this.$disconnect(); + } +}; +exports.PrismaService = PrismaService; +exports.PrismaService = PrismaService = __decorate([ + (0, common_1.Injectable)() +], PrismaService); +//# sourceMappingURL=prisma.service.js.map \ No newline at end of file diff --git a/dist/prisma/prisma.service.js.map b/dist/prisma/prisma.service.js.map new file mode 100644 index 0000000..3075bc9 --- /dev/null +++ b/dist/prisma/prisma.service.js.map @@ -0,0 +1 @@ +{"version":3,"file":"prisma.service.js","sourceRoot":"","sources":["../../src/prisma/prisma.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA2E;AAC3E,2CAA8C;AAGvC,IAAM,aAAa,GAAnB,MAAM,aACX,SAAQ,qBAAY;IAGpB,KAAK,CAAC,YAAY;QAChB,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,eAAe;QACnB,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;IAC3B,CAAC;CACF,CAAA;AAXY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;GACA,aAAa,CAWzB"} \ No newline at end of file diff --git a/dist/products/dto/product.dto.d.ts b/dist/products/dto/product.dto.d.ts new file mode 100644 index 0000000..6817640 --- /dev/null +++ b/dist/products/dto/product.dto.d.ts @@ -0,0 +1,36 @@ +export declare class CreateProductDto { + companyId: string; + catalogId: string; + name: string; + code: string; + productCode?: string; + color: string; + description?: string; + minMeterage?: number; + orderMultiplier?: number; + orderStep?: number; + basePrice?: number | null; + price?: number | null; + stock?: number | null; + internalStock?: number | null; + isActive?: boolean; +} +export declare class UpdateProductDto { + catalogId?: string; + name?: string; + code?: string; + productCode?: string; + color?: string; + description?: string | null; + minMeterage?: number; + orderMultiplier?: number; + orderStep?: number; + basePrice?: number | null; + price?: number | null; + stock?: number | null; + internalStock?: number | null; + isActive?: boolean; +} +export declare class SetProductActiveDto { + isActive: boolean; +} diff --git a/dist/products/dto/product.dto.js b/dist/products/dto/product.dto.js new file mode 100644 index 0000000..ed899a9 --- /dev/null +++ b/dist/products/dto/product.dto.js @@ -0,0 +1,231 @@ +"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.SetProductActiveDto = exports.UpdateProductDto = exports.CreateProductDto = void 0; +const class_validator_1 = require("class-validator"); +const class_transformer_1 = require("class-transformer"); +class CreateProductDto { + companyId; + catalogId; + name; + code; + productCode; + color; + description; + minMeterage; + orderMultiplier; + orderStep; + basePrice; + price; + stock; + internalStock; + isActive; +} +exports.CreateProductDto = CreateProductDto; +__decorate([ + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], CreateProductDto.prototype, "companyId", void 0); +__decorate([ + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], CreateProductDto.prototype, "catalogId", void 0); +__decorate([ + (0, class_validator_1.IsString)(), + (0, class_validator_1.MinLength)(1), + __metadata("design:type", String) +], CreateProductDto.prototype, "name", void 0); +__decorate([ + (0, class_validator_1.IsString)(), + (0, class_validator_1.MinLength)(1), + __metadata("design:type", String) +], CreateProductDto.prototype, "code", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], CreateProductDto.prototype, "productCode", void 0); +__decorate([ + (0, class_validator_1.IsString)(), + (0, class_validator_1.MinLength)(1), + __metadata("design:type", String) +], CreateProductDto.prototype, "color", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], CreateProductDto.prototype, "description", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsNumber)(), + (0, class_validator_1.Min)(0), + __metadata("design:type", Number) +], CreateProductDto.prototype, "minMeterage", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsNumber)(), + (0, class_validator_1.Min)(0.001), + __metadata("design:type", Number) +], CreateProductDto.prototype, "orderMultiplier", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsNumber)(), + (0, class_validator_1.Min)(0.001), + __metadata("design:type", Number) +], CreateProductDto.prototype, "orderStep", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsNumber)(), + (0, class_validator_1.Min)(0), + __metadata("design:type", Object) +], CreateProductDto.prototype, "basePrice", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsNumber)(), + (0, class_validator_1.Min)(0), + __metadata("design:type", Object) +], CreateProductDto.prototype, "price", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsNumber)(), + (0, class_validator_1.Min)(0), + __metadata("design:type", Object) +], CreateProductDto.prototype, "stock", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsNumber)(), + (0, class_validator_1.Min)(0), + __metadata("design:type", Object) +], CreateProductDto.prototype, "internalStock", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsBoolean)(), + __metadata("design:type", Boolean) +], CreateProductDto.prototype, "isActive", void 0); +class UpdateProductDto { + catalogId; + name; + code; + productCode; + color; + description; + minMeterage; + orderMultiplier; + orderStep; + basePrice; + price; + stock; + internalStock; + isActive; +} +exports.UpdateProductDto = UpdateProductDto; +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], UpdateProductDto.prototype, "catalogId", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + (0, class_validator_1.MinLength)(1), + __metadata("design:type", String) +], UpdateProductDto.prototype, "name", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + (0, class_validator_1.MinLength)(1), + __metadata("design:type", String) +], UpdateProductDto.prototype, "code", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], UpdateProductDto.prototype, "productCode", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], UpdateProductDto.prototype, "color", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", Object) +], UpdateProductDto.prototype, "description", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsNumber)(), + (0, class_validator_1.Min)(0), + __metadata("design:type", Number) +], UpdateProductDto.prototype, "minMeterage", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsNumber)(), + (0, class_validator_1.Min)(0.001), + __metadata("design:type", Number) +], UpdateProductDto.prototype, "orderMultiplier", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsNumber)(), + (0, class_validator_1.Min)(0.001), + __metadata("design:type", Number) +], UpdateProductDto.prototype, "orderStep", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsNumber)(), + (0, class_validator_1.Min)(0), + __metadata("design:type", Object) +], UpdateProductDto.prototype, "basePrice", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsNumber)(), + (0, class_validator_1.Min)(0), + __metadata("design:type", Object) +], UpdateProductDto.prototype, "price", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsNumber)(), + (0, class_validator_1.Min)(0), + __metadata("design:type", Object) +], UpdateProductDto.prototype, "stock", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsNumber)(), + (0, class_validator_1.Min)(0), + __metadata("design:type", Object) +], UpdateProductDto.prototype, "internalStock", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsBoolean)(), + __metadata("design:type", Boolean) +], UpdateProductDto.prototype, "isActive", void 0); +class SetProductActiveDto { + isActive; +} +exports.SetProductActiveDto = SetProductActiveDto; +__decorate([ + (0, class_validator_1.IsBoolean)(), + __metadata("design:type", Boolean) +], SetProductActiveDto.prototype, "isActive", void 0); +//# sourceMappingURL=product.dto.js.map \ No newline at end of file diff --git a/dist/products/dto/product.dto.js.map b/dist/products/dto/product.dto.js.map new file mode 100644 index 0000000..2665725 --- /dev/null +++ b/dist/products/dto/product.dto.js.map @@ -0,0 +1 @@ +{"version":3,"file":"product.dto.js","sourceRoot":"","sources":["../../../src/products/dto/product.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAOyB;AACzB,yDAAyC;AAEzC,MAAa,gBAAgB;IAE3B,SAAS,C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G,EAAE,CAAC,MAAM,CAAC;IAClB,IAAA,0BAAQ,GAAE;IACV,IAAA,qBAAG,EAAC,CAAC,CAAC;;uDACuB;AAI9B;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,2BAAS,GAAE;;kDACO;AAGrB,MAAa,mBAAmB;IAE9B,QAAQ,CAAW;CACpB;AAHD,kDAGC;AADC;IADC,IAAA,2BAAS,GAAE;;qDACO"} \ No newline at end of file diff --git a/dist/products/products.controller.d.ts b/dist/products/products.controller.d.ts new file mode 100644 index 0000000..44da5d3 --- /dev/null +++ b/dist/products/products.controller.d.ts @@ -0,0 +1,121 @@ +import { ProductsService } from './products.service'; +import { CreateProductDto, SetProductActiveDto, UpdateProductDto } from './dto/product.dto'; +export declare class ProductsController { + private readonly productsService; + constructor(productsService: ProductsService); + findAll(catalogId?: string, companyId?: string, color?: string, activeOnly?: string): Promise<{ + id: string; + companyId: string; + companyName: string; + catalogId: string; + catalogCode: string; + catalogName: string; + name: string; + code: string; + productCode: string; + color: string; + description: string | undefined; + minMeterage: number; + orderMultiplier: number; + orderStep: number; + basePrice: number | null; + price: number | null; + stock: number | null; + internalStock: number; + isActive: boolean; + createdAt: string; + updatedAt: string; + }[]>; + findOne(id: string): Promise<{ + id: string; + companyId: string; + companyName: string; + catalogId: string; + catalogCode: string; + catalogName: string; + name: string; + code: string; + productCode: string; + color: string; + description: string | undefined; + minMeterage: number; + orderMultiplier: number; + orderStep: number; + basePrice: number | null; + price: number | null; + stock: number | null; + internalStock: number; + isActive: boolean; + createdAt: string; + updatedAt: string; + }>; + create(dto: CreateProductDto): Promise<{ + id: string; + companyId: string; + companyName: string; + catalogId: string; + catalogCode: string; + catalogName: string; + name: string; + code: string; + productCode: string; + color: string; + description: string | undefined; + minMeterage: number; + orderMultiplier: number; + orderStep: number; + basePrice: number | null; + price: number | null; + stock: number | null; + internalStock: number; + isActive: boolean; + createdAt: string; + updatedAt: string; + }>; + update(id: string, dto: UpdateProductDto): Promise<{ + id: string; + companyId: string; + companyName: string; + catalogId: string; + catalogCode: string; + catalogName: string; + name: string; + code: string; + productCode: string; + color: string; + description: string | undefined; + minMeterage: number; + orderMultiplier: number; + orderStep: number; + basePrice: number | null; + price: number | null; + stock: number | null; + internalStock: number; + isActive: boolean; + createdAt: string; + updatedAt: string; + }>; + setActive(id: string, dto: SetProductActiveDto): Promise<{ + id: string; + companyId: string; + companyName: string; + catalogId: string; + catalogCode: string; + catalogName: string; + name: string; + code: string; + productCode: string; + color: string; + description: string | undefined; + minMeterage: number; + orderMultiplier: number; + orderStep: number; + basePrice: number | null; + price: number | null; + stock: number | null; + internalStock: number; + isActive: boolean; + createdAt: string; + updatedAt: string; + }>; +} diff --git a/dist/products/products.controller.js b/dist/products/products.controller.js new file mode 100644 index 0000000..5ce4bdc --- /dev/null +++ b/dist/products/products.controller.js @@ -0,0 +1,96 @@ +"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.ProductsController = void 0; +const common_1 = require("@nestjs/common"); +const products_service_1 = require("./products.service"); +const auth_decorators_1 = require("../common/decorators/auth.decorators"); +const product_dto_1 = require("./dto/product.dto"); +let ProductsController = class ProductsController { + productsService; + constructor(productsService) { + this.productsService = productsService; + } + findAll(catalogId, companyId, color, activeOnly) { + return this.productsService.findAll({ + catalogId, + companyId, + color, + activeOnly: activeOnly === 'true' || activeOnly === '1', + }); + } + findOne(id) { + return this.productsService.findOne(id); + } + create(dto) { + return this.productsService.create(dto); + } + update(id, dto) { + return this.productsService.update(id, dto); + } + setActive(id, dto) { + return this.productsService.setActive(id, dto.isActive); + } +}; +exports.ProductsController = ProductsController; +__decorate([ + (0, auth_decorators_1.AuthType)('any'), + (0, common_1.Get)(), + __param(0, (0, common_1.Query)('catalogId')), + __param(1, (0, common_1.Query)('companyId')), + __param(2, (0, common_1.Query)('color')), + __param(3, (0, common_1.Query)('activeOnly')), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String, String, String, String]), + __metadata("design:returntype", void 0) +], ProductsController.prototype, "findAll", null); +__decorate([ + (0, auth_decorators_1.AuthType)('any'), + (0, common_1.Get)(':id'), + __param(0, (0, common_1.Param)('id')), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String]), + __metadata("design:returntype", void 0) +], ProductsController.prototype, "findOne", null); +__decorate([ + (0, auth_decorators_1.AuthType)('admin'), + (0, common_1.Post)(), + __param(0, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [product_dto_1.CreateProductDto]), + __metadata("design:returntype", void 0) +], ProductsController.prototype, "create", null); +__decorate([ + (0, auth_decorators_1.AuthType)('admin'), + (0, common_1.Patch)(':id'), + __param(0, (0, common_1.Param)('id')), + __param(1, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String, product_dto_1.UpdateProductDto]), + __metadata("design:returntype", void 0) +], ProductsController.prototype, "update", null); +__decorate([ + (0, auth_decorators_1.AuthType)('admin'), + (0, common_1.Patch)(':id/active'), + __param(0, (0, common_1.Param)('id')), + __param(1, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String, product_dto_1.SetProductActiveDto]), + __metadata("design:returntype", void 0) +], ProductsController.prototype, "setActive", null); +exports.ProductsController = ProductsController = __decorate([ + (0, common_1.Controller)('products'), + __metadata("design:paramtypes", [products_service_1.ProductsService]) +], ProductsController); +//# sourceMappingURL=products.controller.js.map \ No newline at end of file diff --git a/dist/products/products.controller.js.map b/dist/products/products.controller.js.map new file mode 100644 index 0000000..640ec7c --- /dev/null +++ b/dist/products/products.controller.js.map @@ -0,0 +1 @@ +{"version":3,"file":"products.controller.js","sourceRoot":"","sources":["../../src/products/products.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAQwB;AACxB,yDAAqD;AACrD,0EAAgE;AAChE,mDAI2B;AAGpB,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IACA;IAA7B,YAA6B,eAAgC;QAAhC,oBAAe,GAAf,eAAe,CAAiB;IAAG,CAAC;IAIjE,OAAO,CACe,SAAkB,EAClB,SAAkB,EACtB,KAAc,EACT,UAAmB;QAExC,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC;YAClC,SAAS;YACT,SAAS;YACT,KAAK;YACL,UAAU,EAAE,UAAU,KAAK,MAAM,IAAI,UAAU,KAAK,GAAG;SACxD,CAAC,CAAC;IACL,CAAC;IAID,OAAO,CAAc,EAAU;QAC7B,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC1C,CAAC;IAID,MAAM,CAAS,GAAqB;QAClC,OAAO,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC1C,CAAC;IAID,MAAM,CAAc,EAAU,EAAU,GAAqB;QAC3D,OAAO,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IAC9C,CAAC;IAID,SAAS,CAAc,EAAU,EAAU,GAAwB;QACjE,OAAO,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC1D,CAAC;CACF,CAAA;AA1CY,gDAAkB;AAK7B;IAFC,IAAA,0BAAQ,EAAC,KAAK,CAAC;IACf,IAAA,YAAG,GAAE;IAEH,WAAA,IAAA,cAAK,EAAC,WAAW,CAAC,CAAA;IAClB,WAAA,IAAA,cAAK,EAAC,WAAW,CAAC,CAAA;IAClB,WAAA,IAAA,cAAK,EAAC,OAAO,CAAC,CAAA;IACd,WAAA,IAAA,cAAK,EAAC,YAAY,CAAC,CAAA;;;;iDAQrB;AAID;IAFC,IAAA,0BAAQ,EAAC,KAAK,CAAC;IACf,IAAA,YAAG,EAAC,KAAK,CAAC;IACF,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;;;;iDAEnB;AAID;IAFC,IAAA,0BAAQ,EAAC,OAAO,CAAC;IACjB,IAAA,aAAI,GAAE;IACC,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAM,8BAAgB;;gDAEnC;AAID;IAFC,IAAA,0BAAQ,EAAC,OAAO,CAAC;IACjB,IAAA,cAAK,EAAC,KAAK,CAAC;IACL,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;IAAc,WAAA,IAAA,aAAI,GAAE,CAAA;;6CAAM,8BAAgB;;gDAE5D;AAID;IAFC,IAAA,0BAAQ,EAAC,OAAO,CAAC;IACjB,IAAA,cAAK,EAAC,YAAY,CAAC;IACT,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;IAAc,WAAA,IAAA,aAAI,GAAE,CAAA;;6CAAM,iCAAmB;;mDAElE;6BAzCU,kBAAkB;IAD9B,IAAA,mBAAU,EAAC,UAAU,CAAC;qCAEyB,kCAAe;GADlD,kBAAkB,CA0C9B"} \ No newline at end of file diff --git a/dist/products/products.module.d.ts b/dist/products/products.module.d.ts new file mode 100644 index 0000000..0886307 --- /dev/null +++ b/dist/products/products.module.d.ts @@ -0,0 +1,2 @@ +export declare class ProductsModule { +} diff --git a/dist/products/products.module.js b/dist/products/products.module.js new file mode 100644 index 0000000..f8f8781 --- /dev/null +++ b/dist/products/products.module.js @@ -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.ProductsModule = void 0; +const common_1 = require("@nestjs/common"); +const products_controller_1 = require("./products.controller"); +const products_service_1 = require("./products.service"); +let ProductsModule = class ProductsModule { +}; +exports.ProductsModule = ProductsModule; +exports.ProductsModule = ProductsModule = __decorate([ + (0, common_1.Module)({ + controllers: [products_controller_1.ProductsController], + providers: [products_service_1.ProductsService], + exports: [products_service_1.ProductsService], + }) +], ProductsModule); +//# sourceMappingURL=products.module.js.map \ No newline at end of file diff --git a/dist/products/products.module.js.map b/dist/products/products.module.js.map new file mode 100644 index 0000000..f74bba2 --- /dev/null +++ b/dist/products/products.module.js.map @@ -0,0 +1 @@ +{"version":3,"file":"products.module.js","sourceRoot":"","sources":["../../src/products/products.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,+DAA2D;AAC3D,yDAAqD;AAO9C,IAAM,cAAc,GAApB,MAAM,cAAc;CAAG,CAAA;AAAjB,wCAAc;yBAAd,cAAc;IAL1B,IAAA,eAAM,EAAC;QACN,WAAW,EAAE,CAAC,wCAAkB,CAAC;QACjC,SAAS,EAAE,CAAC,kCAAe,CAAC;QAC5B,OAAO,EAAE,CAAC,kCAAe,CAAC;KAC3B,CAAC;GACW,cAAc,CAAG"} \ No newline at end of file diff --git a/dist/products/products.service.d.ts b/dist/products/products.service.d.ts new file mode 100644 index 0000000..d169a30 --- /dev/null +++ b/dist/products/products.service.d.ts @@ -0,0 +1,129 @@ +import { PrismaService } from '../prisma/prisma.service'; +import { CreateProductDto, UpdateProductDto } from './dto/product.dto'; +export declare class ProductsService { + private readonly prisma; + constructor(prisma: PrismaService); + findAll(filters: { + catalogId?: string; + companyId?: string; + color?: string; + activeOnly?: boolean; + }): Promise<{ + id: string; + companyId: string; + companyName: string; + catalogId: string; + catalogCode: string; + catalogName: string; + name: string; + code: string; + productCode: string; + color: string; + description: string | undefined; + minMeterage: number; + orderMultiplier: number; + orderStep: number; + basePrice: number | null; + price: number | null; + stock: number | null; + internalStock: number; + isActive: boolean; + createdAt: string; + updatedAt: string; + }[]>; + findOne(id: string): Promise<{ + id: string; + companyId: string; + companyName: string; + catalogId: string; + catalogCode: string; + catalogName: string; + name: string; + code: string; + productCode: string; + color: string; + description: string | undefined; + minMeterage: number; + orderMultiplier: number; + orderStep: number; + basePrice: number | null; + price: number | null; + stock: number | null; + internalStock: number; + isActive: boolean; + createdAt: string; + updatedAt: string; + }>; + create(dto: CreateProductDto): Promise<{ + id: string; + companyId: string; + companyName: string; + catalogId: string; + catalogCode: string; + catalogName: string; + name: string; + code: string; + productCode: string; + color: string; + description: string | undefined; + minMeterage: number; + orderMultiplier: number; + orderStep: number; + basePrice: number | null; + price: number | null; + stock: number | null; + internalStock: number; + isActive: boolean; + createdAt: string; + updatedAt: string; + }>; + update(id: string, dto: UpdateProductDto): Promise<{ + id: string; + companyId: string; + companyName: string; + catalogId: string; + catalogCode: string; + catalogName: string; + name: string; + code: string; + productCode: string; + color: string; + description: string | undefined; + minMeterage: number; + orderMultiplier: number; + orderStep: number; + basePrice: number | null; + price: number | null; + stock: number | null; + internalStock: number; + isActive: boolean; + createdAt: string; + updatedAt: string; + }>; + setActive(id: string, isActive: boolean): Promise<{ + id: string; + companyId: string; + companyName: string; + catalogId: string; + catalogCode: string; + catalogName: string; + name: string; + code: string; + productCode: string; + color: string; + description: string | undefined; + minMeterage: number; + orderMultiplier: number; + orderStep: number; + basePrice: number | null; + price: number | null; + stock: number | null; + internalStock: number; + isActive: boolean; + createdAt: string; + updatedAt: string; + }>; + private pickNumber; + private ensure; + private map; +} diff --git a/dist/products/products.service.js b/dist/products/products.service.js new file mode 100644 index 0000000..9cb5561 --- /dev/null +++ b/dist/products/products.service.js @@ -0,0 +1,196 @@ +"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.ProductsService = void 0; +const common_1 = require("@nestjs/common"); +const client_1 = require("@prisma/client"); +const prisma_service_1 = require("../prisma/prisma.service"); +let ProductsService = class ProductsService { + prisma; + constructor(prisma) { + this.prisma = prisma; + } + async findAll(filters) { + const products = await this.prisma.product.findMany({ + where: { + ...(filters.catalogId ? { catalogId: filters.catalogId } : {}), + ...(filters.companyId ? { companyId: filters.companyId } : {}), + ...(filters.color + ? { color: { contains: filters.color, mode: 'insensitive' } } + : {}), + ...(filters.activeOnly ? { isActive: true } : {}), + }, + orderBy: [{ name: 'asc' }, { color: 'asc' }], + include: { + company: { select: { name: true } }, + catalog: { select: { code: true, name: true } }, + }, + }); + return products.map((p) => this.map(p)); + } + async findOne(id) { + const product = await this.prisma.product.findUnique({ + where: { id }, + include: { + company: { select: { name: true } }, + catalog: { select: { code: true, name: true } }, + }, + }); + if (!product) + throw new common_1.NotFoundException('محصول یافت نشد'); + return this.map(product); + } + async create(dto) { + const catalog = await this.prisma.catalog.findUnique({ + where: { id: dto.catalogId }, + }); + if (!catalog) + throw new common_1.NotFoundException('کاتالوگ یافت نشد'); + if (catalog.companyId !== dto.companyId) { + throw new common_1.ConflictException('کاتالوگ متعلق به این شرکت نیست'); + } + const code = (dto.code || dto.productCode || '').trim(); + if (!code) + throw new common_1.ConflictException('کد محصول الزامی است'); + try { + const product = await this.prisma.product.create({ + data: { + companyId: dto.companyId, + catalogId: dto.catalogId, + name: dto.name.trim(), + code, + color: dto.color.trim(), + description: dto.description?.trim() || null, + minMeterage: dto.minMeterage ?? 30, + orderMultiplier: dto.orderMultiplier ?? dto.orderStep ?? 10, + basePrice: this.pickNumber(dto.basePrice, dto.price), + stock: this.pickNumber(dto.stock, dto.internalStock), + isActive: dto.isActive ?? true, + }, + include: { + company: { select: { name: true } }, + catalog: { select: { code: true, name: true } }, + }, + }); + return this.map(product); + } + catch (e) { + if (e instanceof client_1.Prisma.PrismaClientKnownRequestError && e.code === 'P2002') { + throw new common_1.ConflictException('کد محصول در این شرکت تکراری است'); + } + throw e; + } + } + async update(id, dto) { + await this.ensure(id); + const code = dto.code !== undefined + ? dto.code.trim() + : dto.productCode !== undefined + ? dto.productCode.trim() + : undefined; + try { + const product = await this.prisma.product.update({ + where: { id }, + data: { + catalogId: dto.catalogId, + name: dto.name?.trim(), + code, + color: dto.color?.trim(), + description: dto.description === undefined + ? undefined + : dto.description?.trim() || null, + minMeterage: dto.minMeterage, + orderMultiplier: dto.orderMultiplier !== undefined + ? dto.orderMultiplier + : dto.orderStep, + basePrice: dto.basePrice !== undefined + ? dto.basePrice + : dto.price !== undefined + ? dto.price + : undefined, + stock: dto.stock !== undefined + ? dto.stock + : dto.internalStock !== undefined + ? dto.internalStock + : undefined, + isActive: dto.isActive, + }, + include: { + company: { select: { name: true } }, + catalog: { select: { code: true, name: true } }, + }, + }); + return this.map(product); + } + catch (e) { + if (e instanceof client_1.Prisma.PrismaClientKnownRequestError && e.code === 'P2002') { + throw new common_1.ConflictException('کد محصول در این شرکت تکراری است'); + } + throw e; + } + } + async setActive(id, isActive) { + await this.ensure(id); + const product = await this.prisma.product.update({ + where: { id }, + data: { isActive }, + include: { + company: { select: { name: true } }, + catalog: { select: { code: true, name: true } }, + }, + }); + return this.map(product); + } + pickNumber(primary, alias) { + if (primary !== undefined) + return primary; + if (alias !== undefined) + return alias; + return null; + } + async ensure(id) { + const product = await this.prisma.product.findUnique({ where: { id } }); + if (!product) + throw new common_1.NotFoundException('محصول یافت نشد'); + return product; + } + map(product) { + return { + id: product.id, + companyId: product.companyId, + companyName: product.company.name, + catalogId: product.catalogId, + catalogCode: product.catalog.code, + catalogName: product.catalog.name, + name: product.name, + code: product.code, + productCode: product.code, + color: product.color, + description: product.description ?? undefined, + minMeterage: product.minMeterage, + orderMultiplier: product.orderMultiplier, + orderStep: product.orderMultiplier, + basePrice: product.basePrice, + price: product.basePrice, + stock: product.stock, + internalStock: product.stock ?? 0, + isActive: product.isActive, + createdAt: product.createdAt.toISOString(), + updatedAt: product.updatedAt.toISOString(), + }; + } +}; +exports.ProductsService = ProductsService; +exports.ProductsService = ProductsService = __decorate([ + (0, common_1.Injectable)(), + __metadata("design:paramtypes", [prisma_service_1.PrismaService]) +], ProductsService); +//# sourceMappingURL=products.service.js.map \ No newline at end of file diff --git a/dist/products/products.service.js.map b/dist/products/products.service.js.map new file mode 100644 index 0000000..c2cc8fc --- /dev/null +++ b/dist/products/products.service.js.map @@ -0,0 +1 @@ +{"version":3,"file":"products.service.js","sourceRoot":"","sources":["../../src/products/products.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAIwB;AACxB,2CAAwC;AACxC,6DAAyD;AAIlD,IAAM,eAAe,GAArB,MAAM,eAAe;IACG;IAA7B,YAA6B,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;IAEtD,KAAK,CAAC,OAAO,CAAC,OAKb;QACC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC;YAClD,KAAK,EAAE;gBACL,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,C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,CAAC,CAAC;QAC5D,OAAO,OAAO,CAAC;IACjB,CAAC;IAEO,GAAG,CAAC,OAiBX;QACC,OAAO;YACL,EAAE,EAAE,OAAO,CAAC,EAAE;YACd,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,WAAW,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI;YACjC,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,WAAW,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI;YACjC,WAAW,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI;YACjC,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,WAAW,EAAE,OAAO,CAAC,IAAI;YACzB,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,SAAS;YAC7C,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,eAAe,EAAE,OAAO,CAAC,eAAe;YACxC,SAAS,EAAE,OAAO,CAAC,eAAe;YAClC,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,KAAK,EAAE,OAAO,CAAC,SAAS;YACxB,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,aAAa,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;YACjC,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,WAAW,EAAE;YAC1C,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,WAAW,EAAE;SAC3C,CAAC;IACJ,CAAC;CACF,CAAA;AA5MY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;qCAE0B,8BAAa;GADvC,eAAe,CA4M3B"} \ No newline at end of file diff --git a/dist/settings/dto/settings.dto.d.ts b/dist/settings/dto/settings.dto.d.ts new file mode 100644 index 0000000..d914df9 --- /dev/null +++ b/dist/settings/dto/settings.dto.d.ts @@ -0,0 +1,12 @@ +export declare class UpdateSettingsDto { + maxMeteragePerInvoice?: number; + cashInvoiceValidityHours?: number; + defaultSettlementCheck?: boolean; + defaultSettlementCash?: boolean; + smsOrderRegistered?: boolean; + smsPaymentReminder?: boolean; + smsCheckReview?: boolean; + smsShippingUpdate?: boolean; + supportPhone?: string | null; + supportEmail?: string | null; +} diff --git a/dist/settings/dto/settings.dto.js b/dist/settings/dto/settings.dto.js new file mode 100644 index 0000000..91525c8 --- /dev/null +++ b/dist/settings/dto/settings.dto.js @@ -0,0 +1,82 @@ +"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.UpdateSettingsDto = void 0; +const class_validator_1 = require("class-validator"); +const class_transformer_1 = require("class-transformer"); +class UpdateSettingsDto { + maxMeteragePerInvoice; + cashInvoiceValidityHours; + defaultSettlementCheck; + defaultSettlementCash; + smsOrderRegistered; + smsPaymentReminder; + smsCheckReview; + smsShippingUpdate; + supportPhone; + supportEmail; +} +exports.UpdateSettingsDto = UpdateSettingsDto; +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsInt)(), + (0, class_validator_1.Min)(1), + __metadata("design:type", Number) +], UpdateSettingsDto.prototype, "maxMeteragePerInvoice", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsInt)(), + (0, class_validator_1.Min)(1), + __metadata("design:type", Number) +], UpdateSettingsDto.prototype, "cashInvoiceValidityHours", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsBoolean)(), + __metadata("design:type", Boolean) +], UpdateSettingsDto.prototype, "defaultSettlementCheck", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsBoolean)(), + __metadata("design:type", Boolean) +], UpdateSettingsDto.prototype, "defaultSettlementCash", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsBoolean)(), + __metadata("design:type", Boolean) +], UpdateSettingsDto.prototype, "smsOrderRegistered", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsBoolean)(), + __metadata("design:type", Boolean) +], UpdateSettingsDto.prototype, "smsPaymentReminder", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsBoolean)(), + __metadata("design:type", Boolean) +], UpdateSettingsDto.prototype, "smsCheckReview", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsBoolean)(), + __metadata("design:type", Boolean) +], UpdateSettingsDto.prototype, "smsShippingUpdate", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", Object) +], UpdateSettingsDto.prototype, "supportPhone", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", Object) +], UpdateSettingsDto.prototype, "supportEmail", void 0); +//# sourceMappingURL=settings.dto.js.map \ No newline at end of file diff --git a/dist/settings/dto/settings.dto.js.map b/dist/settings/dto/settings.dto.js.map new file mode 100644 index 0000000..7324775 --- /dev/null +++ b/dist/settings/dto/settings.dto.js.map @@ -0,0 +1 @@ +{"version":3,"file":"settings.dto.js","sourceRoot":"","sources":["../../../src/settings/dto/settings.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAA8E;AAC9E,yDAAyC;AAEzC,MAAa,iBAAiB;IAK5B,qBAAqB,CAAU;IAM/B,wBAAwB,CAAU;IAIlC,sBAAsB,CAAW;IAIjC,qBAAqB,CAAW;IAIhC,kBAAkB,CAAW;IAI7B,kBAAkB,CAAW;IAI7B,cAAc,CAAW;IAIzB,iBAAiB,CAAW;IAI5B,YAAY,CAAiB;IAI7B,YAAY,CAAiB;CAC9B;AA5CD,8CA4CC;AAvCC;IAJC,IAAA,4BAAU,GAAE;IACZ,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC;IAClB,IAAA,uBAAK,GAAE;IACP,IAAA,qBAAG,EAAC,CAAC,CAAC;;gEACwB;AAM/B;IAJC,IAAA,4BAAU,GAAE;IACZ,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC;IAClB,IAAA,uBAAK,GAAE;IACP,IAAA,qBAAG,EAAC,CAAC,CAAC;;mEAC2B;AAIlC;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,2BAAS,GAAE;;iEACqB;AAIjC;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,2BAAS,GAAE;;gEACoB;AAIhC;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,2BAAS,GAAE;;6DACiB;AAI7B;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,2BAAS,GAAE;;6DACiB;AAI7B;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,2BAAS,GAAE;;yDACa;AAIzB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,2BAAS,GAAE;;4DACgB;AAI5B;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;uDACkB;AAI7B;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;uDACkB"} \ No newline at end of file diff --git a/dist/settings/settings.controller.d.ts b/dist/settings/settings.controller.d.ts new file mode 100644 index 0000000..116fd87 --- /dev/null +++ b/dist/settings/settings.controller.d.ts @@ -0,0 +1,34 @@ +import { SettingsService } from './settings.service'; +import { UpdateSettingsDto } from './dto/settings.dto'; +export declare class SettingsController { + private readonly settingsService; + constructor(settingsService: SettingsService); + get(): Promise<{ + id: string; + maxMeteragePerInvoice: number; + cashInvoiceValidityHours: number; + defaultSettlementCheck: boolean; + defaultSettlementCash: boolean; + smsOrderRegistered: boolean; + smsPaymentReminder: boolean; + smsCheckReview: boolean; + smsShippingUpdate: boolean; + supportPhone: string | null; + supportEmail: string | null; + updatedAt: string; + }>; + update(dto: UpdateSettingsDto): Promise<{ + id: string; + maxMeteragePerInvoice: number; + cashInvoiceValidityHours: number; + defaultSettlementCheck: boolean; + defaultSettlementCash: boolean; + smsOrderRegistered: boolean; + smsPaymentReminder: boolean; + smsCheckReview: boolean; + smsShippingUpdate: boolean; + supportPhone: string | null; + supportEmail: string | null; + updatedAt: string; + }>; +} diff --git a/dist/settings/settings.controller.js b/dist/settings/settings.controller.js new file mode 100644 index 0000000..e7e344f --- /dev/null +++ b/dist/settings/settings.controller.js @@ -0,0 +1,51 @@ +"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.SettingsController = void 0; +const common_1 = require("@nestjs/common"); +const settings_service_1 = require("./settings.service"); +const auth_decorators_1 = require("../common/decorators/auth.decorators"); +const settings_dto_1 = require("./dto/settings.dto"); +let SettingsController = class SettingsController { + settingsService; + constructor(settingsService) { + this.settingsService = settingsService; + } + get() { + return this.settingsService.get(); + } + update(dto) { + return this.settingsService.update(dto); + } +}; +exports.SettingsController = SettingsController; +__decorate([ + (0, common_1.Get)(), + __metadata("design:type", Function), + __metadata("design:paramtypes", []), + __metadata("design:returntype", void 0) +], SettingsController.prototype, "get", null); +__decorate([ + (0, common_1.Patch)(), + __param(0, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [settings_dto_1.UpdateSettingsDto]), + __metadata("design:returntype", void 0) +], SettingsController.prototype, "update", null); +exports.SettingsController = SettingsController = __decorate([ + (0, common_1.Controller)('admin/settings'), + (0, auth_decorators_1.AuthType)('admin'), + __metadata("design:paramtypes", [settings_service_1.SettingsService]) +], SettingsController); +//# sourceMappingURL=settings.controller.js.map \ No newline at end of file diff --git a/dist/settings/settings.controller.js.map b/dist/settings/settings.controller.js.map new file mode 100644 index 0000000..b670a26 --- /dev/null +++ b/dist/settings/settings.controller.js.map @@ -0,0 +1 @@ +{"version":3,"file":"settings.controller.js","sourceRoot":"","sources":["../../src/settings/settings.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA8D;AAC9D,yDAAqD;AACrD,0EAAgE;AAChE,qDAAuD;AAIhD,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IACA;IAA7B,YAA6B,eAAgC;QAAhC,oBAAe,GAAf,eAAe,CAAiB;IAAG,CAAC;IAGjE,GAAG;QACD,OAAO,IAAI,CAAC,eAAe,CAAC,GAAG,EAAE,CAAC;IACpC,CAAC;IAGD,MAAM,CAAS,GAAsB;QACnC,OAAO,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC1C,CAAC;CACF,CAAA;AAZY,gDAAkB;AAI7B;IADC,IAAA,YAAG,GAAE;;;;6CAGL;AAGD;IADC,IAAA,cAAK,GAAE;IACA,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAM,gCAAiB;;gDAEpC;6BAXU,kBAAkB;IAF9B,IAAA,mBAAU,EAAC,gBAAgB,CAAC;IAC5B,IAAA,0BAAQ,EAAC,OAAO,CAAC;qCAE8B,kCAAe;GADlD,kBAAkB,CAY9B"} \ No newline at end of file diff --git a/dist/settings/settings.module.d.ts b/dist/settings/settings.module.d.ts new file mode 100644 index 0000000..c52d9c8 --- /dev/null +++ b/dist/settings/settings.module.d.ts @@ -0,0 +1,2 @@ +export declare class SettingsModule { +} diff --git a/dist/settings/settings.module.js b/dist/settings/settings.module.js new file mode 100644 index 0000000..11a83a0 --- /dev/null +++ b/dist/settings/settings.module.js @@ -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.SettingsModule = void 0; +const common_1 = require("@nestjs/common"); +const settings_controller_1 = require("./settings.controller"); +const settings_service_1 = require("./settings.service"); +let SettingsModule = class SettingsModule { +}; +exports.SettingsModule = SettingsModule; +exports.SettingsModule = SettingsModule = __decorate([ + (0, common_1.Module)({ + controllers: [settings_controller_1.SettingsController], + providers: [settings_service_1.SettingsService], + exports: [settings_service_1.SettingsService], + }) +], SettingsModule); +//# sourceMappingURL=settings.module.js.map \ No newline at end of file diff --git a/dist/settings/settings.module.js.map b/dist/settings/settings.module.js.map new file mode 100644 index 0000000..ce9102a --- /dev/null +++ b/dist/settings/settings.module.js.map @@ -0,0 +1 @@ +{"version":3,"file":"settings.module.js","sourceRoot":"","sources":["../../src/settings/settings.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,+DAA2D;AAC3D,yDAAqD;AAO9C,IAAM,cAAc,GAApB,MAAM,cAAc;CAAG,CAAA;AAAjB,wCAAc;yBAAd,cAAc;IAL1B,IAAA,eAAM,EAAC;QACN,WAAW,EAAE,CAAC,wCAAkB,CAAC;QACjC,SAAS,EAAE,CAAC,kCAAe,CAAC;QAC5B,OAAO,EAAE,CAAC,kCAAe,CAAC;KAC3B,CAAC;GACW,cAAc,CAAG"} \ No newline at end of file diff --git a/dist/settings/settings.service.d.ts b/dist/settings/settings.service.d.ts new file mode 100644 index 0000000..5da4bce --- /dev/null +++ b/dist/settings/settings.service.d.ts @@ -0,0 +1,36 @@ +import { PrismaService } from '../prisma/prisma.service'; +import { UpdateSettingsDto } from './dto/settings.dto'; +export declare class SettingsService { + private readonly prisma; + constructor(prisma: PrismaService); + get(): Promise<{ + id: string; + maxMeteragePerInvoice: number; + cashInvoiceValidityHours: number; + defaultSettlementCheck: boolean; + defaultSettlementCash: boolean; + smsOrderRegistered: boolean; + smsPaymentReminder: boolean; + smsCheckReview: boolean; + smsShippingUpdate: boolean; + supportPhone: string | null; + supportEmail: string | null; + updatedAt: string; + }>; + update(dto: UpdateSettingsDto): Promise<{ + id: string; + maxMeteragePerInvoice: number; + cashInvoiceValidityHours: number; + defaultSettlementCheck: boolean; + defaultSettlementCash: boolean; + smsOrderRegistered: boolean; + smsPaymentReminder: boolean; + smsCheckReview: boolean; + smsShippingUpdate: boolean; + supportPhone: string | null; + supportEmail: string | null; + updatedAt: string; + }>; + private ensureDefaults; + private map; +} diff --git a/dist/settings/settings.service.js b/dist/settings/settings.service.js new file mode 100644 index 0000000..4475e76 --- /dev/null +++ b/dist/settings/settings.service.js @@ -0,0 +1,76 @@ +"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.SettingsService = void 0; +const common_1 = require("@nestjs/common"); +const prisma_service_1 = require("../prisma/prisma.service"); +let SettingsService = class SettingsService { + prisma; + constructor(prisma) { + this.prisma = prisma; + } + async get() { + const settings = await this.ensureDefaults(); + return this.map(settings); + } + async update(dto) { + await this.ensureDefaults(); + const settings = await this.prisma.systemSettings.update({ + where: { id: 'default' }, + data: { + maxMeteragePerInvoice: dto.maxMeteragePerInvoice, + cashInvoiceValidityHours: dto.cashInvoiceValidityHours, + defaultSettlementCheck: dto.defaultSettlementCheck, + defaultSettlementCash: dto.defaultSettlementCash, + smsOrderRegistered: dto.smsOrderRegistered, + smsPaymentReminder: dto.smsPaymentReminder, + smsCheckReview: dto.smsCheckReview, + smsShippingUpdate: dto.smsShippingUpdate, + supportPhone: dto.supportPhone === undefined + ? undefined + : dto.supportPhone?.trim() || null, + supportEmail: dto.supportEmail === undefined + ? undefined + : dto.supportEmail?.trim() || null, + }, + }); + return this.map(settings); + } + async ensureDefaults() { + return this.prisma.systemSettings.upsert({ + where: { id: 'default' }, + create: { id: 'default' }, + update: {}, + }); + } + map(settings) { + return { + id: settings.id, + maxMeteragePerInvoice: settings.maxMeteragePerInvoice, + cashInvoiceValidityHours: settings.cashInvoiceValidityHours, + defaultSettlementCheck: settings.defaultSettlementCheck, + defaultSettlementCash: settings.defaultSettlementCash, + smsOrderRegistered: settings.smsOrderRegistered, + smsPaymentReminder: settings.smsPaymentReminder, + smsCheckReview: settings.smsCheckReview, + smsShippingUpdate: settings.smsShippingUpdate, + supportPhone: settings.supportPhone, + supportEmail: settings.supportEmail, + updatedAt: settings.updatedAt.toISOString(), + }; + } +}; +exports.SettingsService = SettingsService; +exports.SettingsService = SettingsService = __decorate([ + (0, common_1.Injectable)(), + __metadata("design:paramtypes", [prisma_service_1.PrismaService]) +], SettingsService); +//# sourceMappingURL=settings.service.js.map \ No newline at end of file diff --git a/dist/settings/settings.service.js.map b/dist/settings/settings.service.js.map new file mode 100644 index 0000000..83dbe2d --- /dev/null +++ b/dist/settings/settings.service.js.map @@ -0,0 +1 @@ +{"version":3,"file":"settings.service.js","sourceRoot":"","sources":["../../src/settings/settings.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,6DAAyD;AAIlD,IAAM,eAAe,GAArB,MAAM,eAAe;IACG;IAA7B,YAA6B,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;IAEtD,KAAK,CAAC,GAAG;QACP,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;QAC7C,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAsB;QACjC,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;QAC5B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC;YACvD,KAAK,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE;YACxB,IAAI,EAAE;gBACJ,qBAAqB,EAAE,GAAG,CAAC,qBAAqB;gBAChD,wBAAwB,EAAE,GAAG,CAAC,wBAAwB;gBACtD,sBAAsB,EAAE,GAAG,CAAC,sBAAsB;gBAClD,qBAAqB,EAAE,GAAG,CAAC,qBAAqB;gBAChD,kBAAkB,EAAE,GAAG,CAAC,kBAAkB;gBAC1C,kBAAkB,EAAE,GAAG,CAAC,kBAAkB;gBAC1C,cAAc,EAAE,GAAG,CAAC,cAA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AAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;qCAE0B,8BAAa;GADvC,eAAe,CAuE3B"} \ No newline at end of file diff --git a/dist/shipments/dto/shipment.dto.d.ts b/dist/shipments/dto/shipment.dto.d.ts new file mode 100644 index 0000000..b5322fa --- /dev/null +++ b/dist/shipments/dto/shipment.dto.d.ts @@ -0,0 +1,18 @@ +import { ShipmentStatus } from '@prisma/client'; +export declare class CreateShipmentDto { + orderId: string; + carrier: string; + trackingNumber?: string; + meterage?: number; + status?: ShipmentStatus; +} +export declare class UpdateShipmentDto { + carrier?: string; + trackingNumber?: string; + meterage?: number; + status?: ShipmentStatus; +} +export declare class AdvanceShipmentStatusDto { + status?: ShipmentStatus; + trackingNumber?: string; +} diff --git a/dist/shipments/dto/shipment.dto.js b/dist/shipments/dto/shipment.dto.js new file mode 100644 index 0000000..929a9d7 --- /dev/null +++ b/dist/shipments/dto/shipment.dto.js @@ -0,0 +1,94 @@ +"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.AdvanceShipmentStatusDto = exports.UpdateShipmentDto = exports.CreateShipmentDto = void 0; +const class_validator_1 = require("class-validator"); +const class_transformer_1 = require("class-transformer"); +const client_1 = require("@prisma/client"); +class CreateShipmentDto { + orderId; + carrier; + trackingNumber; + meterage; + status; +} +exports.CreateShipmentDto = CreateShipmentDto; +__decorate([ + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], CreateShipmentDto.prototype, "orderId", void 0); +__decorate([ + (0, class_validator_1.IsString)(), + (0, class_validator_1.MinLength)(1), + __metadata("design:type", String) +], CreateShipmentDto.prototype, "carrier", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], CreateShipmentDto.prototype, "trackingNumber", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsNumber)(), + (0, class_validator_1.Min)(0), + __metadata("design:type", Number) +], CreateShipmentDto.prototype, "meterage", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsEnum)(client_1.ShipmentStatus), + __metadata("design:type", String) +], CreateShipmentDto.prototype, "status", void 0); +class UpdateShipmentDto { + carrier; + trackingNumber; + meterage; + status; +} +exports.UpdateShipmentDto = UpdateShipmentDto; +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], UpdateShipmentDto.prototype, "carrier", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], UpdateShipmentDto.prototype, "trackingNumber", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_transformer_1.Type)(() => Number), + (0, class_validator_1.IsNumber)(), + (0, class_validator_1.Min)(0), + __metadata("design:type", Number) +], UpdateShipmentDto.prototype, "meterage", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsEnum)(client_1.ShipmentStatus), + __metadata("design:type", String) +], UpdateShipmentDto.prototype, "status", void 0); +class AdvanceShipmentStatusDto { + status; + trackingNumber; +} +exports.AdvanceShipmentStatusDto = AdvanceShipmentStatusDto; +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsEnum)(client_1.ShipmentStatus), + __metadata("design:type", String) +], AdvanceShipmentStatusDto.prototype, "status", void 0); +__decorate([ + (0, class_validator_1.IsOptional)(), + (0, class_validator_1.IsString)(), + __metadata("design:type", String) +], AdvanceShipmentStatusDto.prototype, "trackingNumber", void 0); +//# sourceMappingURL=shipment.dto.js.map \ No newline at end of file diff --git a/dist/shipments/dto/shipment.dto.js.map b/dist/shipments/dto/shipment.dto.js.map new file mode 100644 index 0000000..99fff78 --- /dev/null +++ b/dist/shipments/dto/shipment.dto.js.map @@ -0,0 +1 @@ +{"version":3,"file":"shipment.dto.js","sourceRoot":"","sources":["../../../src/shipments/dto/shipment.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAOyB;AACzB,yDAAyC;AACzC,2CAAgD;AAEhD,MAAa,iBAAiB;IAE5B,OAAO,CAAU;IAIjB,OAAO,CAAU;IAIjB,cAAc,CAAU;IAMxB,QAAQ,CAAU;IAIlB,MAAM,CAAkB;CACzB;AArBD,8CAqBC;AAnBC;IADC,IAAA,0BAAQ,GAAE;;kDACM;AAIjB;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,2BAAS,EAAC,CAAC,CAAC;;kDACI;AAIjB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;yDACa;AAMxB;IAJC,IAAA,4BAAU,GAAE;IACZ,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC;IAClB,IAAA,0BAAQ,GAAE;IACV,IAAA,qBAAG,EAAC,CAAC,CAAC;;mDACW;AAIlB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,wBAAM,EAAC,uBAAc,CAAC;;iDACC;AAG1B,MAAa,iBAAiB;IAG5B,OAAO,CAAU;IAIjB,cAAc,CAAU;IAMxB,QAAQ,CAAU;IAIlB,MAAM,CAAkB;CACzB;AAlBD,8CAkBC;AAfC;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;kDACM;AAIjB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;yDACa;AAMxB;IAJC,IAAA,4BAAU,GAAE;IACZ,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC;IAClB,IAAA,0BAAQ,GAAE;IACV,IAAA,qBAAG,EAAC,CAAC,CAAC;;mDACW;AAIlB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,wBAAM,EAAC,uBAAc,CAAC;;iDACC;AAG1B,MAAa,wBAAwB;IAGnC,MAAM,CAAkB;IAIxB,cAAc,CAAU;CACzB;AARD,4DAQC;AALC;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,wBAAM,EAAC,uBAAc,CAAC;;wDACC;AAIxB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;gEACa"} \ No newline at end of file diff --git a/dist/shipments/shipments.controller.d.ts b/dist/shipments/shipments.controller.d.ts new file mode 100644 index 0000000..c360fcc --- /dev/null +++ b/dist/shipments/shipments.controller.d.ts @@ -0,0 +1,78 @@ +import { ShipmentStatus } from '@prisma/client'; +import { ShipmentsService } from './shipments.service'; +import type { AuthPrincipal } from '../common/decorators/current-user.decorator'; +import { AdvanceShipmentStatusDto, CreateShipmentDto, UpdateShipmentDto } from './dto/shipment.dto'; +export declare class ShipmentsController { + private readonly shipmentsService; + constructor(shipmentsService: ShipmentsService); + findAll(status?: ShipmentStatus): Promise<{ + id: string; + orderId: string; + orderNumber: string; + customerName: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + createdAt: string; + updatedAt: string; + }[]>; + findOne(id: string): Promise<{ + id: string; + orderId: string; + orderNumber: string; + customerName: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + createdAt: string; + updatedAt: string; + }>; + create(user: AuthPrincipal, dto: CreateShipmentDto): Promise<{ + id: string; + orderId: string; + orderNumber: string; + customerName: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + createdAt: string; + updatedAt: string; + }>; + update(id: string, dto: UpdateShipmentDto): Promise<{ + id: string; + orderId: string; + orderNumber: string; + customerName: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + createdAt: string; + updatedAt: string; + }>; + advanceStatus(user: AuthPrincipal, id: string, dto: AdvanceShipmentStatusDto): Promise<{ + id: string; + orderId: string; + orderNumber: string; + customerName: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + createdAt: string; + updatedAt: string; + }>; +} diff --git a/dist/shipments/shipments.controller.js b/dist/shipments/shipments.controller.js new file mode 100644 index 0000000..ebaf2e1 --- /dev/null +++ b/dist/shipments/shipments.controller.js @@ -0,0 +1,88 @@ +"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.ShipmentsController = void 0; +const common_1 = require("@nestjs/common"); +const client_1 = require("@prisma/client"); +const shipments_service_1 = require("./shipments.service"); +const auth_decorators_1 = require("../common/decorators/auth.decorators"); +const current_user_decorator_1 = require("../common/decorators/current-user.decorator"); +const shipment_dto_1 = require("./dto/shipment.dto"); +let ShipmentsController = class ShipmentsController { + shipmentsService; + constructor(shipmentsService) { + this.shipmentsService = shipmentsService; + } + findAll(status) { + return this.shipmentsService.findAll(status); + } + findOne(id) { + return this.shipmentsService.findOne(id); + } + create(user, dto) { + return this.shipmentsService.create(user.id, dto); + } + update(id, dto) { + return this.shipmentsService.update(id, dto); + } + advanceStatus(user, id, dto) { + return this.shipmentsService.advanceStatus(id, user.id, dto); + } +}; +exports.ShipmentsController = ShipmentsController; +__decorate([ + (0, common_1.Get)(), + __param(0, (0, common_1.Query)('status')), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String]), + __metadata("design:returntype", void 0) +], ShipmentsController.prototype, "findAll", null); +__decorate([ + (0, common_1.Get)(':id'), + __param(0, (0, common_1.Param)('id')), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String]), + __metadata("design:returntype", void 0) +], ShipmentsController.prototype, "findOne", null); +__decorate([ + (0, common_1.Post)(), + __param(0, (0, current_user_decorator_1.CurrentUser)()), + __param(1, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [Object, shipment_dto_1.CreateShipmentDto]), + __metadata("design:returntype", void 0) +], ShipmentsController.prototype, "create", null); +__decorate([ + (0, common_1.Patch)(':id'), + __param(0, (0, common_1.Param)('id')), + __param(1, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [String, shipment_dto_1.UpdateShipmentDto]), + __metadata("design:returntype", void 0) +], ShipmentsController.prototype, "update", null); +__decorate([ + (0, common_1.Patch)(':id/status'), + __param(0, (0, current_user_decorator_1.CurrentUser)()), + __param(1, (0, common_1.Param)('id')), + __param(2, (0, common_1.Body)()), + __metadata("design:type", Function), + __metadata("design:paramtypes", [Object, String, shipment_dto_1.AdvanceShipmentStatusDto]), + __metadata("design:returntype", void 0) +], ShipmentsController.prototype, "advanceStatus", null); +exports.ShipmentsController = ShipmentsController = __decorate([ + (0, common_1.Controller)('admin/shipments'), + (0, auth_decorators_1.AuthType)('admin'), + __metadata("design:paramtypes", [shipments_service_1.ShipmentsService]) +], ShipmentsController); +//# sourceMappingURL=shipments.controller.js.map \ No newline at end of file diff --git a/dist/shipments/shipments.controller.js.map b/dist/shipments/shipments.controller.js.map new file mode 100644 index 0000000..e4b7b37 --- /dev/null +++ b/dist/shipments/shipments.controller.js.map @@ -0,0 +1 @@ +{"version":3,"file":"shipments.controller.js","sourceRoot":"","sources":["../../src/shipments/shipments.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAQwB;AACxB,2CAAgD;AAChD,2DAAuD;AACvD,0EAAgE;AAChE,wFAA0E;AAE1E,qDAI4B;AAIrB,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IACD;IAA7B,YAA6B,gBAAkC;QAAlC,qBAAgB,GAAhB,gBAAgB,CAAkB;IAAG,CAAC;IAGnE,OAAO,CAAkB,MAAuB;QAC9C,OAAO,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/C,CAAC;IAGD,OAAO,CAAc,EAAU;QAC7B,OAAO,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC3C,CAAC;IAGD,MAAM,CACW,IAAmB,EAC1B,GAAsB;QAE9B,OAAO,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IACpD,CAAC;IAGD,MAAM,CAAc,EAAU,EAAU,GAAsB;QAC5D,OAAO,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IAC/C,CAAC;IAGD,aAAa,CACI,IAAmB,EACrB,EAAU,EACf,GAA6B;QAErC,OAAO,IAAI,CAAC,gBAAgB,CAAC,aAAa,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IAC/D,CAAC;CACF,CAAA;AAlCY,kDAAmB;AAI9B;IADC,IAAA,YAAG,GAAE;IACG,WAAA,IAAA,cAAK,EAAC,QAAQ,CAAC,CAAA;;;;kDAEvB;AAGD;IADC,IAAA,YAAG,EAAC,KAAK,CAAC;IACF,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;;;;kDAEnB;AAGD;IADC,IAAA,aAAI,GAAE;IAEJ,WAAA,IAAA,oCAAW,GAAE,CAAA;IACb,WAAA,IAAA,aAAI,GAAE,CAAA;;6CAAM,gCAAiB;;iDAG/B;AAGD;IADC,IAAA,cAAK,EAAC,KAAK,CAAC;IACL,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;IAAc,WAAA,IAAA,aAAI,GAAE,CAAA;;6CAAM,gCAAiB;;iDAE7D;AAGD;IADC,IAAA,cAAK,EAAC,YAAY,CAAC;IAEjB,WAAA,IAAA,oCAAW,GAAE,CAAA;IACb,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;IACX,WAAA,IAAA,aAAI,GAAE,CAAA;;qDAAM,uCAAwB;;wDAGtC;8BAjCU,mBAAmB;IAF/B,IAAA,mBAAU,EAAC,iBAAiB,CAAC;IAC7B,IAAA,0BAAQ,EAAC,OAAO,CAAC;qCAE+B,oCAAgB;GADpD,mBAAmB,CAkC/B"} \ No newline at end of file diff --git a/dist/shipments/shipments.module.d.ts b/dist/shipments/shipments.module.d.ts new file mode 100644 index 0000000..80e2cd9 --- /dev/null +++ b/dist/shipments/shipments.module.d.ts @@ -0,0 +1,2 @@ +export declare class ShipmentsModule { +} diff --git a/dist/shipments/shipments.module.js b/dist/shipments/shipments.module.js new file mode 100644 index 0000000..2931e53 --- /dev/null +++ b/dist/shipments/shipments.module.js @@ -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.ShipmentsModule = void 0; +const common_1 = require("@nestjs/common"); +const shipments_controller_1 = require("./shipments.controller"); +const shipments_service_1 = require("./shipments.service"); +let ShipmentsModule = class ShipmentsModule { +}; +exports.ShipmentsModule = ShipmentsModule; +exports.ShipmentsModule = ShipmentsModule = __decorate([ + (0, common_1.Module)({ + controllers: [shipments_controller_1.ShipmentsController], + providers: [shipments_service_1.ShipmentsService], + exports: [shipments_service_1.ShipmentsService], + }) +], ShipmentsModule); +//# sourceMappingURL=shipments.module.js.map \ No newline at end of file diff --git a/dist/shipments/shipments.module.js.map b/dist/shipments/shipments.module.js.map new file mode 100644 index 0000000..831964d --- /dev/null +++ b/dist/shipments/shipments.module.js.map @@ -0,0 +1 @@ +{"version":3,"file":"shipments.module.js","sourceRoot":"","sources":["../../src/shipments/shipments.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,iEAA6D;AAC7D,2DAAuD;AAOhD,IAAM,eAAe,GAArB,MAAM,eAAe;CAAG,CAAA;AAAlB,0CAAe;0BAAf,eAAe;IAL3B,IAAA,eAAM,EAAC;QACN,WAAW,EAAE,CAAC,0CAAmB,CAAC;QAClC,SAAS,EAAE,CAAC,oCAAgB,CAAC;QAC7B,OAAO,EAAE,CAAC,oCAAgB,CAAC;KAC5B,CAAC;GACW,eAAe,CAAG"} \ No newline at end of file diff --git a/dist/shipments/shipments.service.d.ts b/dist/shipments/shipments.service.d.ts new file mode 100644 index 0000000..80d9892 --- /dev/null +++ b/dist/shipments/shipments.service.d.ts @@ -0,0 +1,79 @@ +import { ShipmentStatus } from '@prisma/client'; +import { PrismaService } from '../prisma/prisma.service'; +import { AdvanceShipmentStatusDto, CreateShipmentDto, UpdateShipmentDto } from './dto/shipment.dto'; +export declare class ShipmentsService { + private readonly prisma; + constructor(prisma: PrismaService); + findAll(status?: ShipmentStatus): Promise<{ + id: string; + orderId: string; + orderNumber: string; + customerName: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + createdAt: string; + updatedAt: string; + }[]>; + findOne(id: string): Promise<{ + id: string; + orderId: string; + orderNumber: string; + customerName: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + createdAt: string; + updatedAt: string; + }>; + create(adminId: string, dto: CreateShipmentDto): Promise<{ + id: string; + orderId: string; + orderNumber: string; + customerName: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + createdAt: string; + updatedAt: string; + }>; + update(id: string, dto: UpdateShipmentDto): Promise<{ + id: string; + orderId: string; + orderNumber: string; + customerName: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + createdAt: string; + updatedAt: string; + }>; + advanceStatus(id: string, adminId: string, dto: AdvanceShipmentStatusDto): Promise<{ + id: string; + orderId: string; + orderNumber: string; + customerName: string; + carrier: string; + trackingNumber: string; + meterage: number; + status: import("@prisma/client").$Enums.ShipmentStatus; + shippedAt: string | null; + deliveredAt: string | null; + createdAt: string; + updatedAt: string; + }>; + private ensure; + private map; +} diff --git a/dist/shipments/shipments.service.js b/dist/shipments/shipments.service.js new file mode 100644 index 0000000..dd616d4 --- /dev/null +++ b/dist/shipments/shipments.service.js @@ -0,0 +1,193 @@ +"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.ShipmentsService = void 0; +const common_1 = require("@nestjs/common"); +const client_1 = require("@prisma/client"); +const prisma_service_1 = require("../prisma/prisma.service"); +const name_1 = require("../common/utils/name"); +const STATUS_FLOW = [ + client_1.ShipmentStatus.preparing, + client_1.ShipmentStatus.ready, + client_1.ShipmentStatus.shipped, + client_1.ShipmentStatus.delivered, +]; +const SHIPMENT_TO_ORDER = { + preparing: client_1.OrderStatus.preparing, + ready: client_1.OrderStatus.ready_to_ship, + shipped: client_1.OrderStatus.shipped, + delivered: client_1.OrderStatus.delivered, +}; +let ShipmentsService = class ShipmentsService { + prisma; + constructor(prisma) { + this.prisma = prisma; + } + async findAll(status) { + const shipments = await this.prisma.shipment.findMany({ + where: status ? { status } : undefined, + orderBy: { createdAt: 'desc' }, + include: { + order: { include: { user: true } }, + }, + }); + return shipments.map((s) => this.map(s)); + } + async findOne(id) { + const shipment = await this.prisma.shipment.findUnique({ + where: { id }, + include: { order: { include: { user: true } } }, + }); + if (!shipment) + throw new common_1.NotFoundException('ارسال یافت نشد'); + return this.map(shipment); + } + async create(adminId, dto) { + const order = await this.prisma.order.findUnique({ + where: { id: dto.orderId }, + include: { shipment: true, user: true }, + }); + if (!order) + throw new common_1.NotFoundException('سفارش یافت نشد'); + if (order.shipment) { + throw new common_1.ConflictException('برای این سفارش قبلاً ارسال ثبت شده است'); + } + const status = dto.status ?? client_1.ShipmentStatus.preparing; + const shipment = await this.prisma.$transaction(async (tx) => { + const created = await tx.shipment.create({ + data: { + orderId: order.id, + carrier: dto.carrier.trim(), + trackingNumber: dto.trackingNumber?.trim() || null, + meterage: dto.meterage ?? order.totalMeterage, + status, + shippedAt: status === client_1.ShipmentStatus.shipped ? new Date() : null, + deliveredAt: status === client_1.ShipmentStatus.delivered ? new Date() : null, + }, + include: { order: { include: { user: true } } }, + }); + const nextOrderStatus = SHIPMENT_TO_ORDER[status]; + if (order.status !== nextOrderStatus) { + await tx.order.update({ + where: { id: order.id }, + data: { status: nextOrderStatus }, + }); + await tx.orderStatusHistory.create({ + data: { + orderId: order.id, + fromStatus: order.status, + toStatus: nextOrderStatus, + changedBy: `admin:${adminId}`, + note: 'ثبت ارسال', + }, + }); + } + return created; + }); + return this.map(shipment); + } + async update(id, dto) { + await this.ensure(id); + const shipment = await this.prisma.shipment.update({ + where: { id }, + data: { + carrier: dto.carrier?.trim(), + trackingNumber: dto.trackingNumber === undefined + ? undefined + : dto.trackingNumber?.trim() || null, + meterage: dto.meterage, + status: dto.status, + }, + include: { order: { include: { user: true } } }, + }); + return this.map(shipment); + } + async advanceStatus(id, adminId, dto) { + const shipment = await this.prisma.shipment.findUnique({ + where: { id }, + include: { order: { include: { user: true } } }, + }); + if (!shipment) + throw new common_1.NotFoundException('ارسال یافت نشد'); + let nextStatus = dto.status; + if (!nextStatus) { + const idx = STATUS_FLOW.indexOf(shipment.status); + if (idx < 0 || idx >= STATUS_FLOW.length - 1) { + throw new common_1.BadRequestException('وضعیت ارسال قابل پیشرفت نیست'); + } + nextStatus = STATUS_FLOW[idx + 1]; + } + const updated = await this.prisma.$transaction(async (tx) => { + const result = await tx.shipment.update({ + where: { id }, + data: { + status: nextStatus, + trackingNumber: dto.trackingNumber !== undefined + ? dto.trackingNumber.trim() || null + : undefined, + shippedAt: nextStatus === client_1.ShipmentStatus.shipped + ? (shipment.shippedAt ?? new Date()) + : shipment.shippedAt, + deliveredAt: nextStatus === client_1.ShipmentStatus.delivered + ? new Date() + : shipment.deliveredAt, + }, + include: { order: { include: { user: true } } }, + }); + const nextOrderStatus = SHIPMENT_TO_ORDER[nextStatus]; + if (shipment.order.status !== nextOrderStatus) { + await tx.order.update({ + where: { id: shipment.orderId }, + data: { status: nextOrderStatus }, + }); + await tx.orderStatusHistory.create({ + data: { + orderId: shipment.orderId, + fromStatus: shipment.order.status, + toStatus: nextOrderStatus, + changedBy: `admin:${adminId}`, + note: `وضعیت ارسال: ${nextStatus}`, + }, + }); + } + return result; + }); + return this.map(updated); + } + async ensure(id) { + const shipment = await this.prisma.shipment.findUnique({ where: { id } }); + if (!shipment) + throw new common_1.NotFoundException('ارسال یافت نشد'); + return shipment; + } + map(s) { + return { + id: s.id, + orderId: s.orderId, + orderNumber: s.order.orderNumber, + customerName: (0, name_1.joinFullName)(s.order.user.firstName, s.order.user.lastName), + carrier: s.carrier, + trackingNumber: s.trackingNumber ?? '', + meterage: s.meterage, + status: s.status, + shippedAt: s.shippedAt?.toISOString() ?? null, + deliveredAt: s.deliveredAt?.toISOString() ?? null, + createdAt: s.createdAt.toISOString(), + updatedAt: s.updatedAt.toISOString(), + }; + } +}; +exports.ShipmentsService = ShipmentsService; +exports.ShipmentsService = ShipmentsService = __decorate([ + (0, common_1.Injectable)(), + __metadata("design:paramtypes", [prisma_service_1.PrismaService]) +], ShipmentsService); +//# sourceMappingURL=shipments.service.js.map \ No newline at end of file diff --git a/dist/shipments/shipments.service.js.map b/dist/shipments/shipments.service.js.map new file mode 100644 index 0000000..404f124 --- /dev/null +++ b/dist/shipments/shipments.service.js.map @@ -0,0 +1 @@ +{"version":3,"file":"shipments.service.js","sourceRoot":"","sources":["../../src/shipments/shipments.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAKwB;AACxB,2CAA6D;AAC7D,6DAAyD;AAMzD,+CAAoD;AAEpD,MAAM,WAAW,GAAqB;IACpC,uBAAc,CAAC,SAAS;IACxB,uBAAc,CAAC,KAAK;IACpB,uBAAc,CAAC,OAAO;IACtB,uBAAc,CAAC,SAAS;C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IAC3B,CAAC;IAEO,KAAK,CAAC,MAAM,CAAC,EAAU;QAC7B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;QAC1E,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,0BAAiB,CAAC,gBAAgB,CAAC,CAAC;QAC7D,OAAO,QAAQ,CAAC;IAClB,CAAC;IAEO,GAAG,CAAC,CAeX;QACC,OAAO;YACL,EAAE,EAAE,CAAC,CAAC,EAAE;YACR,OAAO,EAAE,CAAC,CAAC,OAAO;YAClB,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,WAAW;YAChC,YAAY,EAAE,IAAA,mBAAY,EAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC;YACzE,OAAO,EAAE,CAAC,CAAC,OAAO;YAClB,cAAc,EAAE,CAAC,CAAC,cAAc,IAAI,EAAE;YACtC,QAAQ,EAAE,CAAC,CAAC,QAAQ;YACpB,MAAM,EAAE,CAAC,CAAC,MAAM;YAChB,SAAS,EAAE,CAAC,CAAC,SAAS,EAAE,WAAW,EAAE,IAAI,IAAI;YAC7C,WAAW,EAAE,CAAC,CAAC,WAAW,EAAE,WAAW,EAAE,IAAI,IAAI;YACjD,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,WAAW,EAAE;YACpC,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,WAAW,EAAE;SACrC,CAAC;IACJ,CAAC;CACF,CAAA;AA9LY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;qCAE0B,8BAAa;GADvC,gBAAgB,CA8L5B"} \ No newline at end of file diff --git a/docker-compose.dist.yml b/docker-compose.dist.yml new file mode 100644 index 0000000..f4db510 --- /dev/null +++ b/docker-compose.dist.yml @@ -0,0 +1,42 @@ +services: + postgres: + image: postgres:16-alpine + container_name: fabric_trade_db + restart: unless-stopped + env_file: + - .env + environment: + POSTGRES_USER: ${POSTGRES_USER:-fabric} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-fabric123} + POSTGRES_DB: ${POSTGRES_DB:-fabric_trade} + ports: + - '${POSTGRES_PORT:-5432}:5432' + volumes: + - fabric_pg_data:/var/lib/postgresql/data + healthcheck: + test: ['CMD-SHELL', 'pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB'] + interval: 5s + timeout: 5s + retries: 10 + + api: + build: + context: . + dockerfile: Dockerfile.dist + args: + NPM_REGISTRY: ${NPM_REGISTRY:-https://registry.npmmirror.com} + container_name: fabric_trade_api + restart: unless-stopped + depends_on: + postgres: + condition: service_healthy + env_file: + - .env + environment: + DATABASE_URL: postgresql://${POSTGRES_USER:-fabric}:${POSTGRES_PASSWORD:-fabric123}@postgres:5432/${POSTGRES_DB:-fabric_trade}?schema=public + PORT: ${PORT:-3000} + ports: + - '127.0.0.1:${API_PORT:-3000}:3000' + +volumes: + fabric_pg_data: diff --git a/package.json b/package.json index 3116ffa..704a1d7 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,9 @@ "start": "nest start", "start:dev": "nest start --watch", "start:debug": "nest start --debug --watch", - "start:prod": "node dist/main", - "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", + "start:prod": "node dist/main.js", + "build:deploy": "bash scripts/build-local-dist.sh", + "docker:dist": "docker compose -f docker-compose.dist.yml up -d --build", "test": "jest", "test:watch": "jest --watch", "test:cov": "jest --coverage", diff --git a/scripts/build-local-dist.sh b/scripts/build-local-dist.sh new file mode 100644 index 0000000..05c98b8 --- /dev/null +++ b/scripts/build-local-dist.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +set -euo pipefail +cd "$(dirname "$0")/.." + +MIRROR="${NPM_REGISTRY:-https://registry.npmmirror.com}" + +echo "==> بیلد لوکال بدون Docker" +echo "==> registry: $MIRROR" + +npm config set registry "$MIRROR" +npm ci --no-audit --no-fund +npx prisma generate +npm run build + +if [ ! -f dist/main.js ]; then + echo "ERROR: dist/main.js ساخته نشد" + ls -la dist || true + exit 1 +fi + +echo "==> OK: dist/main.js آماده است" +echo "بعدی:" +echo " git add dist && git commit -m 'Build dist' && git push" +echo "روی سرور:" +echo " git pull && RUN_SEED=true docker compose -f docker-compose.dist.yml up -d --build" diff --git a/tsconfig.build.json b/tsconfig.build.json index 64f86c6..701e87e 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -1,4 +1,9 @@ { "extends": "./tsconfig.json", + "compilerOptions": { + "rootDir": "./src", + "outDir": "./dist" + }, + "include": ["src/**/*"], "exclude": ["node_modules", "test", "dist", "**/*spec.ts"] }