Deploy via committed dist: local Nest build, server runs with .env
Build on the developer machine without Docker, commit dist/, and run on the server with Dockerfile.dist plus compose env_file. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Vendored
+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 +1 @@
|
||||
{"version":3,"file":"auth.controller.js","sourceRoot":"","sources":["../../src/auth/auth.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoE;AACpE,iDAA6C;AAC7C,6CAKwB;AACxB,0EAAwE;AACxE,wFAA0E;AAInE,IAAM,cAAc,GAApB,MAAM,cAAc;IACI;IAA7B,YAA6B,WAAwB;QAAxB,gBAAW,GAAX,WAAW,CAAa;IAAG,CAAC;IAIzD,MAAM;QACJ,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,kBAAkB,EAAE,CAAC;IACnD,CAAC;IAID,UAAU,CAAS,GAAkB;QACnC,OAAO,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC1C,CAAC;IAID,SAAS,CAAS,GAAiB;QACjC,OAAO,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IACzC,CAAC;IAID,UAAU,CAAS,GAAkB;QACnC,OAAO,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC1C,CAAC;IAID,EAAE,CAAgB,IAAmB;QACnC,OAAO,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACjD,CAAC;IAID,aAAa,CACI,IAAmB,EAC1B,GAAqB;QAE7B,OAAO,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IACtD,CAAC;CACF,CAAA;AAzCY,wCAAc;AAKzB;IAFC,IAAA,wBAAM,GAAE;IACR,IAAA,YAAG,EAAC,QAAQ,CAAC;;;;4CAGb;AAID;IAFC,IAAA,wBAAM,GAAE;IACR,IAAA,aAAI,EAAC,kBAAkB,CAAC;IACb,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAM,wBAAa;;gDAEpC;AAID;IAFC,IAAA,wBAAM,GAAE;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"}
|
||||
Reference in New Issue
Block a user