Deploy via committed dist: local Nest build, server runs with .env
Build on the developer machine without Docker, commit dist/, and run on the server with Dockerfile.dist plus compose env_file. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
node_modules
|
||||
coverage
|
||||
.git
|
||||
.gitignore
|
||||
@@ -11,3 +12,5 @@ test
|
||||
*.spec.ts
|
||||
.pgdata
|
||||
.tools
|
||||
dist-docker
|
||||
src
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
# compiled output
|
||||
/dist
|
||||
# compiled output — dist را برای دیپلوی روی گیت میفرستیم
|
||||
# /dist
|
||||
/dist-docker
|
||||
/node_modules
|
||||
/build
|
||||
|
||||
@@ -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"]
|
||||
+61
@@ -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;
|
||||
}>;
|
||||
}
|
||||
+83
@@ -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
|
||||
@@ -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,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I,GAAE,CAAA;;6CAAM,kCAAiB;;qDAEhE;+BA1BU,oBAAoB;IAFhC,IAAA,mBAAU,EAAC,aAAa,CAAC;IACzB,IAAA,0BAAQ,EAAC,OAAO,CAAC;qCAEgC,uCAAiB;GADtD,oBAAoB,CA2BhC"}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export declare class AdminUsersModule {
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.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
|
||||
+1
@@ -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"}
|
||||
+63
@@ -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;
|
||||
}
|
||||
+160
@@ -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
|
||||
+1
@@ -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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,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;qCAE0B,8BAAa;GADvC,iBAAiB,CAuH7B"}
|
||||
+20
@@ -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;
|
||||
}
|
||||
+103
@@ -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
|
||||
+1
@@ -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"}
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export declare class AppModule {
|
||||
}
|
||||
Vendored
+58
@@ -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
|
||||
Vendored
+1
@@ -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"}
|
||||
Vendored
+60
@@ -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;
|
||||
}>;
|
||||
}
|
||||
Vendored
+98
@@ -0,0 +1,98 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.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
|
||||
Vendored
+1
@@ -0,0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E;IACR,IAAA,aAAI,EAAC,iBAAiB,CAAC;IACb,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAM,uBAAY;;+CAElC;AAID;IAFC,IAAA,wBAAM,GAAE;IACR,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"}
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export declare class AuthModule {
|
||||
}
|
||||
Vendored
+37
@@ -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
|
||||
Vendored
+1
@@ -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"}
|
||||
Vendored
+61
@@ -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;
|
||||
}
|
||||
Vendored
+221
@@ -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
|
||||
Vendored
+1
File diff suppressed because one or more lines are too long
Vendored
+19
@@ -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;
|
||||
}
|
||||
Vendored
+89
@@ -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
|
||||
Vendored
+1
@@ -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"}
|
||||
Vendored
+151
@@ -0,0 +1,151 @@
|
||||
import { CartsService } from './carts.service';
|
||||
import type { AuthPrincipal } from '../common/decorators/current-user.decorator';
|
||||
import { AddCartItemDto, UpdateCartItemMeterageDto, UpdateCartNotesDto } from './dto/cart.dto';
|
||||
export declare class CartsController {
|
||||
private readonly cartsService;
|
||||
constructor(cartsService: CartsService);
|
||||
getCart(user: AuthPrincipal): Promise<{
|
||||
id: string;
|
||||
userId: string;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
notes: string | undefined;
|
||||
items: {
|
||||
id: string;
|
||||
productId: string;
|
||||
catalogCode: string;
|
||||
productName: string;
|
||||
productCode: string;
|
||||
color: string;
|
||||
meterage: number;
|
||||
unitPrice: number | undefined;
|
||||
notes: string | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
}[];
|
||||
totalMeterage: number;
|
||||
itemCount: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}>;
|
||||
addItem(user: AuthPrincipal, dto: AddCartItemDto): Promise<{
|
||||
id: string;
|
||||
userId: string;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
notes: string | undefined;
|
||||
items: {
|
||||
id: string;
|
||||
productId: string;
|
||||
catalogCode: string;
|
||||
productName: string;
|
||||
productCode: string;
|
||||
color: string;
|
||||
meterage: number;
|
||||
unitPrice: number | undefined;
|
||||
notes: string | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
}[];
|
||||
totalMeterage: number;
|
||||
itemCount: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}>;
|
||||
updateItem(user: AuthPrincipal, itemId: string, dto: UpdateCartItemMeterageDto): Promise<{
|
||||
id: string;
|
||||
userId: string;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
notes: string | undefined;
|
||||
items: {
|
||||
id: string;
|
||||
productId: string;
|
||||
catalogCode: string;
|
||||
productName: string;
|
||||
productCode: string;
|
||||
color: string;
|
||||
meterage: number;
|
||||
unitPrice: number | undefined;
|
||||
notes: string | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
}[];
|
||||
totalMeterage: number;
|
||||
itemCount: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}>;
|
||||
removeItem(user: AuthPrincipal, itemId: string): Promise<{
|
||||
id: string;
|
||||
userId: string;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
notes: string | undefined;
|
||||
items: {
|
||||
id: string;
|
||||
productId: string;
|
||||
catalogCode: string;
|
||||
productName: string;
|
||||
productCode: string;
|
||||
color: string;
|
||||
meterage: number;
|
||||
unitPrice: number | undefined;
|
||||
notes: string | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
}[];
|
||||
totalMeterage: number;
|
||||
itemCount: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}>;
|
||||
updateNotes(user: AuthPrincipal, dto: UpdateCartNotesDto): Promise<{
|
||||
id: string;
|
||||
userId: string;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
notes: string | undefined;
|
||||
items: {
|
||||
id: string;
|
||||
productId: string;
|
||||
catalogCode: string;
|
||||
productName: string;
|
||||
productCode: string;
|
||||
color: string;
|
||||
meterage: number;
|
||||
unitPrice: number | undefined;
|
||||
notes: string | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
}[];
|
||||
totalMeterage: number;
|
||||
itemCount: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}>;
|
||||
clear(user: AuthPrincipal): Promise<{
|
||||
id: string;
|
||||
userId: string;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
notes: string | undefined;
|
||||
items: {
|
||||
id: string;
|
||||
productId: string;
|
||||
catalogCode: string;
|
||||
productName: string;
|
||||
productCode: string;
|
||||
color: string;
|
||||
meterage: number;
|
||||
unitPrice: number | undefined;
|
||||
notes: string | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
}[];
|
||||
totalMeterage: number;
|
||||
itemCount: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}>;
|
||||
}
|
||||
Vendored
+98
@@ -0,0 +1,98 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CartsController = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const carts_service_1 = require("./carts.service");
|
||||
const auth_decorators_1 = require("../common/decorators/auth.decorators");
|
||||
const current_user_decorator_1 = require("../common/decorators/current-user.decorator");
|
||||
const cart_dto_1 = require("./dto/cart.dto");
|
||||
let CartsController = class CartsController {
|
||||
cartsService;
|
||||
constructor(cartsService) {
|
||||
this.cartsService = cartsService;
|
||||
}
|
||||
getCart(user) {
|
||||
return this.cartsService.getCart(user.id);
|
||||
}
|
||||
addItem(user, dto) {
|
||||
return this.cartsService.addItem(user.id, dto);
|
||||
}
|
||||
updateItem(user, itemId, dto) {
|
||||
return this.cartsService.updateItem(user.id, itemId, dto);
|
||||
}
|
||||
removeItem(user, itemId) {
|
||||
return this.cartsService.removeItem(user.id, itemId);
|
||||
}
|
||||
updateNotes(user, dto) {
|
||||
return this.cartsService.updateNotes(user.id, dto);
|
||||
}
|
||||
clear(user) {
|
||||
return this.cartsService.clearCart(user.id);
|
||||
}
|
||||
};
|
||||
exports.CartsController = CartsController;
|
||||
__decorate([
|
||||
(0, common_1.Get)(),
|
||||
__param(0, (0, current_user_decorator_1.CurrentUser)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], CartsController.prototype, "getCart", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('items'),
|
||||
__param(0, (0, current_user_decorator_1.CurrentUser)()),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, cart_dto_1.AddCartItemDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], CartsController.prototype, "addItem", null);
|
||||
__decorate([
|
||||
(0, common_1.Patch)('items/:itemId'),
|
||||
__param(0, (0, current_user_decorator_1.CurrentUser)()),
|
||||
__param(1, (0, common_1.Param)('itemId')),
|
||||
__param(2, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, String, cart_dto_1.UpdateCartItemMeterageDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], CartsController.prototype, "updateItem", null);
|
||||
__decorate([
|
||||
(0, common_1.Delete)('items/:itemId'),
|
||||
__param(0, (0, current_user_decorator_1.CurrentUser)()),
|
||||
__param(1, (0, common_1.Param)('itemId')),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, String]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], CartsController.prototype, "removeItem", null);
|
||||
__decorate([
|
||||
(0, common_1.Patch)('notes'),
|
||||
__param(0, (0, current_user_decorator_1.CurrentUser)()),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, cart_dto_1.UpdateCartNotesDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], CartsController.prototype, "updateNotes", null);
|
||||
__decorate([
|
||||
(0, common_1.Delete)(),
|
||||
__param(0, (0, current_user_decorator_1.CurrentUser)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], CartsController.prototype, "clear", null);
|
||||
exports.CartsController = CartsController = __decorate([
|
||||
(0, common_1.Controller)('carts'),
|
||||
(0, auth_decorators_1.AuthType)('customer'),
|
||||
__metadata("design:paramtypes", [carts_service_1.CartsService])
|
||||
], CartsController);
|
||||
//# sourceMappingURL=carts.controller.js.map
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"carts.controller.js","sourceRoot":"","sources":["../../src/carts/carts.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAQwB;AACxB,mDAA+C;AAC/C,0EAAgE;AAChE,wFAA0E;AAE1E,6CAIwB;AAIjB,IAAM,eAAe,GAArB,MAAM,eAAe;IACG;IAA7B,YAA6B,YAA0B;QAA1B,iBAAY,GAAZ,YAAY,CAAc;IAAG,CAAC;IAG3D,OAAO,CAAgB,IAAmB;QACxC,OAAO,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC5C,CAAC;IAGD,OAAO,CACU,IAAmB,EAC1B,GAAmB;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GjB;AAGD;IADC,IAAA,cAAK,EAAC,OAAO,CAAC;IAEZ,WAAA,IAAA,oCAAW,GAAE,CAAA;IACb,WAAA,IAAA,aAAI,GAAE,CAAA;;6CAAM,6BAAkB;;kDAGhC;AAGD;IADC,IAAA,eAAM,GAAE;IACF,WAAA,IAAA,oCAAW,GAAE,CAAA;;;;4CAEnB;0BA5CU,eAAe;IAF3B,IAAA,mBAAU,EAAC,OAAO,CAAC;IACnB,IAAA,0BAAQ,EAAC,UAAU,CAAC;qCAEwB,4BAAY;GAD5C,eAAe,CA6C3B"}
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export declare class CartsModule {
|
||||
}
|
||||
Vendored
+23
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CartsModule = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const carts_controller_1 = require("./carts.controller");
|
||||
const carts_service_1 = require("./carts.service");
|
||||
let CartsModule = class CartsModule {
|
||||
};
|
||||
exports.CartsModule = CartsModule;
|
||||
exports.CartsModule = CartsModule = __decorate([
|
||||
(0, common_1.Module)({
|
||||
controllers: [carts_controller_1.CartsController],
|
||||
providers: [carts_service_1.CartsService],
|
||||
exports: [carts_service_1.CartsService],
|
||||
})
|
||||
], CartsModule);
|
||||
//# sourceMappingURL=carts.module.js.map
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"carts.module.js","sourceRoot":"","sources":["../../src/carts/carts.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,yDAAqD;AACrD,mDAA+C;AAOxC,IAAM,WAAW,GAAjB,MAAM,WAAW;CAAG,CAAA;AAAd,kCAAW;sBAAX,WAAW;IALvB,IAAA,eAAM,EAAC;QACN,WAAW,EAAE,CAAC,kCAAe,CAAC;QAC9B,SAAS,EAAE,CAAC,4BAAY,CAAC;QACzB,OAAO,EAAE,CAAC,4BAAY,CAAC;KACxB,CAAC;GACW,WAAW,CAAG"}
|
||||
Vendored
+153
@@ -0,0 +1,153 @@
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { AddCartItemDto, UpdateCartItemMeterageDto, UpdateCartNotesDto } from './dto/cart.dto';
|
||||
export declare class CartsService {
|
||||
private readonly prisma;
|
||||
constructor(prisma: PrismaService);
|
||||
getCart(userId: string): Promise<{
|
||||
id: string;
|
||||
userId: string;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
notes: string | undefined;
|
||||
items: {
|
||||
id: string;
|
||||
productId: string;
|
||||
catalogCode: string;
|
||||
productName: string;
|
||||
productCode: string;
|
||||
color: string;
|
||||
meterage: number;
|
||||
unitPrice: number | undefined;
|
||||
notes: string | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
}[];
|
||||
totalMeterage: number;
|
||||
itemCount: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}>;
|
||||
addItem(userId: string, dto: AddCartItemDto): Promise<{
|
||||
id: string;
|
||||
userId: string;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
notes: string | undefined;
|
||||
items: {
|
||||
id: string;
|
||||
productId: string;
|
||||
catalogCode: string;
|
||||
productName: string;
|
||||
productCode: string;
|
||||
color: string;
|
||||
meterage: number;
|
||||
unitPrice: number | undefined;
|
||||
notes: string | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
}[];
|
||||
totalMeterage: number;
|
||||
itemCount: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}>;
|
||||
updateItem(userId: string, itemId: string, dto: UpdateCartItemMeterageDto): Promise<{
|
||||
id: string;
|
||||
userId: string;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
notes: string | undefined;
|
||||
items: {
|
||||
id: string;
|
||||
productId: string;
|
||||
catalogCode: string;
|
||||
productName: string;
|
||||
productCode: string;
|
||||
color: string;
|
||||
meterage: number;
|
||||
unitPrice: number | undefined;
|
||||
notes: string | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
}[];
|
||||
totalMeterage: number;
|
||||
itemCount: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}>;
|
||||
removeItem(userId: string, itemId: string): Promise<{
|
||||
id: string;
|
||||
userId: string;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
notes: string | undefined;
|
||||
items: {
|
||||
id: string;
|
||||
productId: string;
|
||||
catalogCode: string;
|
||||
productName: string;
|
||||
productCode: string;
|
||||
color: string;
|
||||
meterage: number;
|
||||
unitPrice: number | undefined;
|
||||
notes: string | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
}[];
|
||||
totalMeterage: number;
|
||||
itemCount: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}>;
|
||||
updateNotes(userId: string, dto: UpdateCartNotesDto): Promise<{
|
||||
id: string;
|
||||
userId: string;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
notes: string | undefined;
|
||||
items: {
|
||||
id: string;
|
||||
productId: string;
|
||||
catalogCode: string;
|
||||
productName: string;
|
||||
productCode: string;
|
||||
color: string;
|
||||
meterage: number;
|
||||
unitPrice: number | undefined;
|
||||
notes: string | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
}[];
|
||||
totalMeterage: number;
|
||||
itemCount: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}>;
|
||||
clearCart(userId: string): Promise<{
|
||||
id: string;
|
||||
userId: string;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
notes: string | undefined;
|
||||
items: {
|
||||
id: string;
|
||||
productId: string;
|
||||
catalogCode: string;
|
||||
productName: string;
|
||||
productCode: string;
|
||||
color: string;
|
||||
meterage: number;
|
||||
unitPrice: number | undefined;
|
||||
notes: string | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
}[];
|
||||
totalMeterage: number;
|
||||
itemCount: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}>;
|
||||
private validateMeterage;
|
||||
private ensureCart;
|
||||
private mapCart;
|
||||
}
|
||||
Vendored
+188
@@ -0,0 +1,188 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CartsService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const prisma_service_1 = require("../prisma/prisma.service");
|
||||
let CartsService = class CartsService {
|
||||
prisma;
|
||||
constructor(prisma) {
|
||||
this.prisma = prisma;
|
||||
}
|
||||
async getCart(userId) {
|
||||
const cart = await this.ensureCart(userId);
|
||||
return this.mapCart(cart);
|
||||
}
|
||||
async addItem(userId, dto) {
|
||||
const product = await this.prisma.product.findUnique({
|
||||
where: { id: dto.productId },
|
||||
include: {
|
||||
catalog: true,
|
||||
company: true,
|
||||
},
|
||||
});
|
||||
if (!product || !product.isActive) {
|
||||
throw new common_1.NotFoundException('محصول یافت نشد');
|
||||
}
|
||||
this.validateMeterage(product, dto.meterage);
|
||||
const cart = await this.ensureCart(userId);
|
||||
const existing = await this.prisma.cartItem.findUnique({
|
||||
where: {
|
||||
cartId_productId: { cartId: cart.id, productId: product.id },
|
||||
},
|
||||
});
|
||||
if (existing) {
|
||||
const newMeterage = existing.meterage + dto.meterage;
|
||||
this.validateMeterage(product, newMeterage);
|
||||
await this.prisma.cartItem.update({
|
||||
where: { id: existing.id },
|
||||
data: {
|
||||
meterage: newMeterage,
|
||||
notes: dto.notes?.trim() || existing.notes,
|
||||
unitPrice: product.basePrice,
|
||||
},
|
||||
});
|
||||
}
|
||||
else {
|
||||
await this.prisma.cartItem.create({
|
||||
data: {
|
||||
cartId: cart.id,
|
||||
productId: product.id,
|
||||
catalogCode: product.catalog.code,
|
||||
productName: product.name,
|
||||
productCode: product.code,
|
||||
color: product.color,
|
||||
meterage: dto.meterage,
|
||||
unitPrice: product.basePrice,
|
||||
notes: dto.notes?.trim() || null,
|
||||
companyId: product.companyId,
|
||||
companyName: product.company.name,
|
||||
},
|
||||
});
|
||||
}
|
||||
await this.prisma.cart.update({
|
||||
where: { id: cart.id },
|
||||
data: {
|
||||
companyId: product.companyId,
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
});
|
||||
return this.getCart(userId);
|
||||
}
|
||||
async updateItem(userId, itemId, dto) {
|
||||
const cart = await this.ensureCart(userId);
|
||||
const item = await this.prisma.cartItem.findFirst({
|
||||
where: { id: itemId, cartId: cart.id },
|
||||
include: { product: true },
|
||||
});
|
||||
if (!item)
|
||||
throw new common_1.NotFoundException('آیتم سبد یافت نشد');
|
||||
this.validateMeterage(item.product, dto.meterage);
|
||||
await this.prisma.cartItem.update({
|
||||
where: { id: itemId },
|
||||
data: {
|
||||
meterage: dto.meterage,
|
||||
notes: dto.notes === undefined ? undefined : dto.notes?.trim() || null,
|
||||
},
|
||||
});
|
||||
await this.prisma.cart.update({
|
||||
where: { id: cart.id },
|
||||
data: { updatedAt: new Date() },
|
||||
});
|
||||
return this.getCart(userId);
|
||||
}
|
||||
async removeItem(userId, itemId) {
|
||||
const cart = await this.ensureCart(userId);
|
||||
const item = await this.prisma.cartItem.findFirst({
|
||||
where: { id: itemId, cartId: cart.id },
|
||||
});
|
||||
if (!item)
|
||||
throw new common_1.NotFoundException('آیتم سبد یافت نشد');
|
||||
await this.prisma.cartItem.delete({ where: { id: itemId } });
|
||||
await this.prisma.cart.update({
|
||||
where: { id: cart.id },
|
||||
data: { updatedAt: new Date() },
|
||||
});
|
||||
return this.getCart(userId);
|
||||
}
|
||||
async updateNotes(userId, dto) {
|
||||
const cart = await this.ensureCart(userId);
|
||||
await this.prisma.cart.update({
|
||||
where: { id: cart.id },
|
||||
data: { notes: dto.notes?.trim() || null },
|
||||
});
|
||||
return this.getCart(userId);
|
||||
}
|
||||
async clearCart(userId) {
|
||||
const cart = await this.ensureCart(userId);
|
||||
await this.prisma.cartItem.deleteMany({ where: { cartId: cart.id } });
|
||||
await this.prisma.cart.update({
|
||||
where: { id: cart.id },
|
||||
data: { notes: null, companyId: null },
|
||||
});
|
||||
return this.getCart(userId);
|
||||
}
|
||||
validateMeterage(product, meterage) {
|
||||
if (meterage < product.minMeterage) {
|
||||
throw new common_1.BadRequestException(`حداقل متراژ برای ${product.name} برابر ${product.minMeterage} است`);
|
||||
}
|
||||
const rem = Math.round((meterage / product.orderMultiplier) * 1000) / 1000;
|
||||
if (Math.abs(rem - Math.round(rem)) > 1e-6) {
|
||||
throw new common_1.BadRequestException(`متراژ باید مضرب ${product.orderMultiplier} باشد`);
|
||||
}
|
||||
}
|
||||
async ensureCart(userId) {
|
||||
let cart = await this.prisma.cart.findFirst({
|
||||
where: { userId },
|
||||
include: { items: true },
|
||||
});
|
||||
if (!cart) {
|
||||
cart = await this.prisma.cart.create({
|
||||
data: { userId },
|
||||
include: { items: true },
|
||||
});
|
||||
}
|
||||
return cart;
|
||||
}
|
||||
mapCart(cart) {
|
||||
const companyName = cart.items[0]?.companyName;
|
||||
return {
|
||||
id: cart.id,
|
||||
userId: cart.userId,
|
||||
companyId: cart.companyId ?? cart.items[0]?.companyId,
|
||||
companyName: companyName ?? '',
|
||||
notes: cart.notes ?? undefined,
|
||||
items: cart.items.map((item) => ({
|
||||
id: item.id,
|
||||
productId: item.productId,
|
||||
catalogCode: item.catalogCode,
|
||||
productName: item.productName,
|
||||
productCode: item.productCode,
|
||||
color: item.color,
|
||||
meterage: item.meterage,
|
||||
unitPrice: item.unitPrice ?? undefined,
|
||||
notes: item.notes ?? undefined,
|
||||
companyId: item.companyId,
|
||||
companyName: item.companyName,
|
||||
})),
|
||||
totalMeterage: cart.items.reduce((s, i) => s + i.meterage, 0),
|
||||
itemCount: cart.items.length,
|
||||
createdAt: cart.createdAt.toISOString(),
|
||||
updatedAt: cart.updatedAt.toISOString(),
|
||||
};
|
||||
}
|
||||
};
|
||||
exports.CartsService = CartsService;
|
||||
exports.CartsService = CartsService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [prisma_service_1.PrismaService])
|
||||
], CartsService);
|
||||
//# sourceMappingURL=carts.service.js.map
|
||||
Vendored
+1
File diff suppressed because one or more lines are too long
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
export declare class AddCartItemDto {
|
||||
productId: string;
|
||||
meterage: number;
|
||||
notes?: string;
|
||||
}
|
||||
export declare class UpdateCartItemMeterageDto {
|
||||
meterage: number;
|
||||
notes?: string;
|
||||
}
|
||||
export declare class UpdateCartNotesDto {
|
||||
notes?: string;
|
||||
}
|
||||
Vendored
+61
@@ -0,0 +1,61 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.UpdateCartNotesDto = exports.UpdateCartItemMeterageDto = exports.AddCartItemDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const class_transformer_1 = require("class-transformer");
|
||||
class AddCartItemDto {
|
||||
productId;
|
||||
meterage;
|
||||
notes;
|
||||
}
|
||||
exports.AddCartItemDto = AddCartItemDto;
|
||||
__decorate([
|
||||
(0, class_validator_1.IsString)(),
|
||||
__metadata("design:type", String)
|
||||
], AddCartItemDto.prototype, "productId", void 0);
|
||||
__decorate([
|
||||
(0, class_transformer_1.Type)(() => Number),
|
||||
(0, class_validator_1.IsNumber)(),
|
||||
(0, class_validator_1.Min)(0.001),
|
||||
__metadata("design:type", Number)
|
||||
], AddCartItemDto.prototype, "meterage", void 0);
|
||||
__decorate([
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
(0, class_validator_1.IsString)(),
|
||||
__metadata("design:type", String)
|
||||
], AddCartItemDto.prototype, "notes", void 0);
|
||||
class UpdateCartItemMeterageDto {
|
||||
meterage;
|
||||
notes;
|
||||
}
|
||||
exports.UpdateCartItemMeterageDto = UpdateCartItemMeterageDto;
|
||||
__decorate([
|
||||
(0, class_transformer_1.Type)(() => Number),
|
||||
(0, class_validator_1.IsNumber)(),
|
||||
(0, class_validator_1.Min)(0.001),
|
||||
__metadata("design:type", Number)
|
||||
], UpdateCartItemMeterageDto.prototype, "meterage", void 0);
|
||||
__decorate([
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
(0, class_validator_1.IsString)(),
|
||||
__metadata("design:type", String)
|
||||
], UpdateCartItemMeterageDto.prototype, "notes", void 0);
|
||||
class UpdateCartNotesDto {
|
||||
notes;
|
||||
}
|
||||
exports.UpdateCartNotesDto = UpdateCartNotesDto;
|
||||
__decorate([
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
(0, class_validator_1.IsString)(),
|
||||
__metadata("design:type", String)
|
||||
], UpdateCartNotesDto.prototype, "notes", void 0);
|
||||
//# sourceMappingURL=cart.dto.js.map
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"cart.dto.js","sourceRoot":"","sources":["../../../src/carts/dto/cart.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAsE;AACtE,yDAAyC;AAEzC,MAAa,cAAc;IAEzB,SAAS,CAAU;IAKnB,QAAQ,CAAU;IAIlB,KAAK,CAAU;CAChB;AAZD,wCAYC;AAVC;IADC,IAAA,0BAAQ,GAAE;;iDACQ;AAKnB;IAHC,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC;IAClB,IAAA,0BAAQ,GAAE;IACV,IAAA,qBAAG,EAAC,KAAK,CAAC;;gDACO;AAIlB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;6CACI;AAGjB,MAAa,yBAAyB;IAIpC,QAAQ,CAAU;IAIlB,KAAK,CAAU;CAChB;AATD,8DASC;AALC;IAHC,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC;IAClB,IAAA,0BAAQ,GAAE;IACV,IAAA,qBAAG,EAAC,KAAK,CAAC;;2DACO;AAIlB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;wDACI;AAGjB,MAAa,kBAAkB;IAG7B,KAAK,CAAU;CAChB;AAJD,gDAIC;AADC;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;iDACI"}
|
||||
@@ -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;
|
||||
}>;
|
||||
}
|
||||
+70
@@ -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
|
||||
@@ -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,sBAAsB;IACJ;IAA7B,YAA6B,mBAAwC;QAAxC,wBAAmB,GAAnB,mBAAmB,CAAqB;IAAG,CAAC;IAIzE,aAAa,CACI,IAAmB,EAChB,OAAe,EACzB,GAAyB;QAEjC,OAAO,IAAI,CAAC,mBAAmB,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;IACvE,CAAC;IAID,OAAO,CAAkB,MAA0B;QACjD,OAAO,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAClD,CAAC;IAID,YAAY,CACK,IAAmB,EACrB,EAAU,EACf,GAA+B;QAEvC,OAAO,IAAI,CAAC,mBAAmB,CAAC,YAAY,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IACjE,CAAC;CACF,CAAA;AA5BY,wDAAsB;AAKjC;IAFC,IAAA,0BAAQ,EAAC,UAAU,CAAC;IACpB,IAAA,aAAI,EAAC,8BAA8B,CAAC;IAElC,WAAA,IAAA,oCAAW,GAAE,CAAA;IACb,WAAA,IAAA,cAAK,EAAC,SAAS,CAAC,CAAA;IAChB,WAAA,IAAA,aAAI,GAAE,CAAA;;qDAAM,uCAAoB;;2DAGlC;AAID;IAFC,IAAA,0BAAQ,EAAC,OAAO,CAAC;IACjB,IAAA,YAAG,EAAC,qBAAqB,CAAC;IAClB,WAAA,IAAA,cAAK,EAAC,QAAQ,CAAC,CAAA;;;;qDAEvB;AAID;IAFC,IAAA,0BAAQ,EAAC,OAAO,CAAC;IACjB,IAAA,cAAK,EAAC,gCAAgC,CAAC;IAErC,WAAA,IAAA,oCAAW,GAAE,CAAA;IACb,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;IACX,WAAA,IAAA,aAAI,GAAE,CAAA;;qDAAM,6CAA0B;;0DAGxC;iCA3BU,sBAAsB;IADlC,IAAA,mBAAU,GAAE;qCAEuC,2CAAmB;GAD1D,sBAAsB,CA4BlC"}
|
||||
@@ -0,0 +1,2 @@
|
||||
export declare class CashPaymentsModule {
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.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
|
||||
@@ -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"}
|
||||
+68
@@ -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;
|
||||
}
|
||||
+175
@@ -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
|
||||
File diff suppressed because one or more lines are too long
+15
@@ -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;
|
||||
}
|
||||
+82
@@ -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
|
||||
@@ -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"}
|
||||
+71
@@ -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;
|
||||
}>;
|
||||
}
|
||||
Vendored
+89
@@ -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
|
||||
+1
@@ -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"}
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export declare class CatalogsModule {
|
||||
}
|
||||
Vendored
+23
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.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
|
||||
Vendored
+1
@@ -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"}
|
||||
Vendored
+73
@@ -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;
|
||||
}
|
||||
Vendored
+144
@@ -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
|
||||
+1
@@ -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,CAAC,CAAC,CAAC,EAAE,CAAC;gBACnC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAC1C;YACD,OAAO,EAAE,CAAC,EAAE,YAAY,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;YACnD,OAAO,EAAE;gBACP,OAAO,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;gBACnC,MAAM,EAAE,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE;aACvC;SACF,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,C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O,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"}
|
||||
Vendored
+18
@@ -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;
|
||||
}
|
||||
Vendored
+98
@@ -0,0 +1,98 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
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
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"catalog.dto.js","sourceRoot":"","sources":["../../../src/catalogs/dto/catalog.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAMyB;AACzB,yDAAyC;AAEzC,MAAa,gBAAgB;IAE3B,SAAS,CAAU;IAInB,IAAI,CAAU;IAId,IAAI,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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;
|
||||
}>;
|
||||
}
|
||||
Vendored
+55
@@ -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
|
||||
Vendored
+1
@@ -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"}
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export declare class ChecksModule {
|
||||
}
|
||||
Vendored
+23
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.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
|
||||
Vendored
+1
@@ -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"}
|
||||
Vendored
+49
@@ -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;
|
||||
}
|
||||
Vendored
+109
@@ -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
|
||||
Vendored
+1
@@ -0,0 +1 @@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I,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"}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
import { CheckStatus } from '@prisma/client';
|
||||
export declare class UpdateCheckStatusDto {
|
||||
status: CheckStatus;
|
||||
note?: string;
|
||||
}
|
||||
Vendored
+29
@@ -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
|
||||
Vendored
+1
@@ -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"}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
export declare const IS_PUBLIC_KEY = "isPublic";
|
||||
export declare const Public: () => import("@nestjs/common").CustomDecorator<string>;
|
||||
export declare const ROLES_KEY = "roles";
|
||||
export declare const Roles: (...roles: string[]) => import("@nestjs/common").CustomDecorator<string>;
|
||||
export declare const AUTH_TYPE_KEY = "authType";
|
||||
export declare const AuthType: (type: "customer" | "admin" | "any") => import("@nestjs/common").CustomDecorator<string>;
|
||||
+14
@@ -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
|
||||
@@ -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"}
|
||||
@@ -0,0 +1,7 @@
|
||||
export interface AuthPrincipal {
|
||||
id: string;
|
||||
type: 'customer' | 'admin';
|
||||
role?: string;
|
||||
phone?: string;
|
||||
}
|
||||
export declare const CurrentUser: (...dataOrPipes: unknown[]) => ParameterDecorator;
|
||||
@@ -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
|
||||
@@ -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"}
|
||||
+11
@@ -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<boolean>;
|
||||
}
|
||||
Vendored
+77
@@ -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
|
||||
+1
@@ -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,I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,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;YAChE,MAAM,IAAI,2BAAkB,CAAC,sBAAsB,CAAC,CAAC;QACvD,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAxDY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,mBAAU,GAAE;qCAGmB,gBAAS;QACR,gBAAU;QACd,sBAAa;GAJ7B,YAAY,CAwDxB"}
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
export declare function computeCashInvoiceExpiry(company: {
|
||||
cashInvoiceValidUntilHour: number | null;
|
||||
cashInvoiceValidityHours: number;
|
||||
}): Date;
|
||||
Vendored
+17
@@ -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
|
||||
Vendored
+1
@@ -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"}
|
||||
Vendored
+13
@@ -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;
|
||||
Vendored
+44
@@ -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
|
||||
Vendored
+1
@@ -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,IA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AClD,eAAe,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,IAAI;QACrE,QAAQ;QACR,QAAQ,EAAE,QAAQ,CAAC,WAAW,EAAE;KACjC,CAAC;AACJ,CAAC"}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
export declare function splitFullName(name: string): {
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
};
|
||||
export declare function joinFullName(firstName: string, lastName: string): string;
|
||||
Vendored
+22
@@ -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
|
||||
Vendored
+1
@@ -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"}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
export declare function generateOrderNumber(date?: Date): string;
|
||||
Vendored
+12
@@ -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
|
||||
+1
@@ -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"}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
import { OrderStatus } from '@prisma/client';
|
||||
export declare const ADMIN_STATUS_MAP: Record<string, OrderStatus[]>;
|
||||
export declare function resolveAdminStatusFilter(status?: string): OrderStatus[] | undefined;
|
||||
export declare function toAdminStatus(status: OrderStatus): string;
|
||||
export declare const ORDER_STATUS_LABELS: Record<OrderStatus, string>;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user