archetecture security fix
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import { prisma } from '../../lib/prisma';
|
||||
type DbClient = Pick<typeof prisma, 'company' | 'brandSettings' | 'contractSettings' | 'subscription' | 'employee'>;
|
||||
type CompanySignupInput = {
|
||||
companyName: string;
|
||||
legalName: string;
|
||||
slug: string;
|
||||
ownerEmail: string;
|
||||
companyEmail: string;
|
||||
companyPhone: string;
|
||||
streetAddress: string;
|
||||
city: string;
|
||||
country: string;
|
||||
zipCode: string;
|
||||
legalForm: string;
|
||||
managerName: string;
|
||||
iceNumber: string;
|
||||
taxId: string;
|
||||
operatingLicenseNumber: string;
|
||||
operatingLicenseIssuedAt: string;
|
||||
operatingLicenseIssuedBy: string;
|
||||
fax?: string;
|
||||
yearsActive: string;
|
||||
representativeName?: string;
|
||||
representativeTitle?: string;
|
||||
responsibleName: string;
|
||||
responsibleRole: string;
|
||||
responsibleIdentityNumber: string;
|
||||
responsibleQualification?: string;
|
||||
responsiblePhone: string;
|
||||
responsibleEmail: string;
|
||||
currency: 'MAD';
|
||||
registrationNumber: string;
|
||||
plan: 'STARTER' | 'GROWTH' | 'PRO';
|
||||
billingPeriod: 'MONTHLY' | 'ANNUAL';
|
||||
preferredLanguage: 'en' | 'fr' | 'ar';
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
passwordHash: string;
|
||||
now: Date;
|
||||
trialEndAt: Date;
|
||||
};
|
||||
export declare function findCompanyBySlug(slug: string): any;
|
||||
export declare function findCompanyByEmail(email: string): any;
|
||||
export declare function findEmployeeByEmail(email: string): any;
|
||||
export declare function createCompanySignup(db: DbClient, input: CompanySignupInput): Promise<{
|
||||
company: any;
|
||||
employee: any;
|
||||
}>;
|
||||
export {};
|
||||
//# sourceMappingURL=auth.company.repo.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.company.repo.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/auth.company.repo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MA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AG,IAAI,GAAG,IAAI,CAAA;IACrC,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,MAAM,CAAA;IACpB,GAAG,EAAE,IAAI,CAAA;IACT,UAAU,EAAE,IAAI,CAAA;CACjB,CAAA;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,OAE7C;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,OAE/C;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,OAEhD;AAED,wBAAsB,mBAAmB,CAAC,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,kBAAkB;;;GAyFhF"}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.findCompanyBySlug = findCompanyBySlug;
|
||||
exports.findCompanyByEmail = findCompanyByEmail;
|
||||
exports.findEmployeeByEmail = findEmployeeByEmail;
|
||||
exports.createCompanySignup = createCompanySignup;
|
||||
const prisma_1 = require("../../lib/prisma");
|
||||
function findCompanyBySlug(slug) {
|
||||
return prisma_1.prisma.company.findUnique({ where: { slug } });
|
||||
}
|
||||
function findCompanyByEmail(email) {
|
||||
return prisma_1.prisma.company.findUnique({ where: { email } });
|
||||
}
|
||||
function findEmployeeByEmail(email) {
|
||||
return prisma_1.prisma.employee.findFirst({ where: { email } });
|
||||
}
|
||||
async function createCompanySignup(db, input) {
|
||||
const company = await db.company.create({
|
||||
data: {
|
||||
name: input.companyName,
|
||||
slug: input.slug,
|
||||
email: input.companyEmail,
|
||||
phone: input.companyPhone,
|
||||
address: {
|
||||
streetAddress: input.streetAddress,
|
||||
city: input.city,
|
||||
country: input.country,
|
||||
zipCode: input.zipCode,
|
||||
legalName: input.legalName,
|
||||
legalForm: input.legalForm,
|
||||
companyEmail: input.companyEmail,
|
||||
managerName: input.managerName,
|
||||
iceNumber: input.iceNumber,
|
||||
operatingLicenseNumber: input.operatingLicenseNumber,
|
||||
operatingLicenseIssuedAt: input.operatingLicenseIssuedAt,
|
||||
operatingLicenseIssuedBy: input.operatingLicenseIssuedBy,
|
||||
fax: input.fax || null,
|
||||
yearsActive: input.yearsActive,
|
||||
representativeName: input.representativeName || null,
|
||||
representativeTitle: input.representativeTitle || null,
|
||||
responsibleName: input.responsibleName,
|
||||
responsibleRole: input.responsibleRole,
|
||||
responsibleIdentityNumber: input.responsibleIdentityNumber,
|
||||
responsibleQualification: input.responsibleQualification || null,
|
||||
responsiblePhone: input.responsiblePhone,
|
||||
responsibleEmail: input.responsibleEmail,
|
||||
},
|
||||
status: 'TRIALING',
|
||||
},
|
||||
});
|
||||
await db.brandSettings.create({
|
||||
data: {
|
||||
companyId: company.id,
|
||||
displayName: input.companyName,
|
||||
subdomain: input.slug,
|
||||
publicEmail: input.companyEmail,
|
||||
publicPhone: input.companyPhone,
|
||||
publicAddress: input.streetAddress,
|
||||
publicCity: input.city,
|
||||
publicCountry: input.country,
|
||||
defaultLocale: input.preferredLanguage,
|
||||
defaultCurrency: input.currency,
|
||||
},
|
||||
});
|
||||
await db.contractSettings.create({
|
||||
data: {
|
||||
companyId: company.id,
|
||||
legalName: input.legalName,
|
||||
registrationNumber: input.registrationNumber,
|
||||
taxId: input.taxId,
|
||||
},
|
||||
});
|
||||
await db.subscription.create({
|
||||
data: {
|
||||
companyId: company.id,
|
||||
plan: input.plan,
|
||||
billingPeriod: input.billingPeriod,
|
||||
currency: input.currency,
|
||||
status: 'TRIALING',
|
||||
trialStartAt: input.now,
|
||||
trialEndAt: input.trialEndAt,
|
||||
currentPeriodStart: input.now,
|
||||
currentPeriodEnd: input.trialEndAt,
|
||||
},
|
||||
});
|
||||
const employee = await db.employee.create({
|
||||
data: {
|
||||
companyId: company.id,
|
||||
clerkUserId: `local_owner_${company.id}`,
|
||||
firstName: input.firstName,
|
||||
lastName: input.lastName,
|
||||
email: input.ownerEmail,
|
||||
phone: input.companyPhone,
|
||||
passwordHash: input.passwordHash,
|
||||
role: 'OWNER',
|
||||
preferredLanguage: input.preferredLanguage,
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
return { company, employee };
|
||||
}
|
||||
//# sourceMappingURL=auth.company.repo.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.company.repo.js","sourceRoot":"","sources":["../../../src/modules/auth/auth.company.repo.ts"],"names":[],"mappings":";;AA4CA,8CAEC;AAED,gDAEC;AAED,kDAEC;AAED,kDAyFC;AAjJD,6CAAyC;AA4CzC,SAAgB,iBAAiB,CAAC,IAAY;IAC5C,OAAO,eAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,CAAA;AACvD,CAAC;AAED,SAAgB,kBAAkB,CAAC,KAAa;IAC9C,OAAO,eAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,CAAA;AACxD,CAAC;AAED,SAAgB,mBAAmB,CAAC,KAAa;IAC/C,OAAO,eAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,CAAA;AACxD,CAAC;AAEM,KAAK,UAAU,mBAAmB,CAAC,EAAY,EAAE,KAAyB;IAC/E,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC;QACtC,IAAI,EAAE;YACJ,IAAI,EAAE,KAAK,CAAC,WAAW;YACvB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,KAAK,EAAE,KAAK,CAAC,YAAY;YACzB,KAAK,EAAE,KAAK,CAAC,YAAY;YACzB,OAAO,EAAE;gBACP,aAAa,EAAE,KAAK,CAAC,aAAa;gBAClC,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,S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||||
@@ -0,0 +1,3 @@
|
||||
declare const router: import("express-serve-static-core").Router;
|
||||
export default router;
|
||||
//# sourceMappingURL=auth.company.routes.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.company.routes.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/auth.company.routes.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,MAAM,4CAAW,CAAA;AAmBvB,eAAe,MAAM,CAAA"}
|
||||
@@ -0,0 +1,60 @@
|
||||
"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 __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;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const express_1 = require("express");
|
||||
const validate_1 = require("../../http/validate");
|
||||
const respond_1 = require("../../http/respond");
|
||||
const auth_company_schemas_1 = require("./auth.company.schemas");
|
||||
const service = __importStar(require("./auth.company.service"));
|
||||
const router = (0, express_1.Router)();
|
||||
router.post('/signup', async (req, res, next) => {
|
||||
try {
|
||||
const body = (0, validate_1.parseBody)(auth_company_schemas_1.companySignupSchema, req);
|
||||
(0, respond_1.created)(res, await service.signup(body));
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
router.post('/complete-signup', (_req, res) => {
|
||||
service.completeSignupDisabled();
|
||||
res.end();
|
||||
});
|
||||
router.post('/verify-email', (_req, res) => {
|
||||
service.verifyEmailDisabled();
|
||||
res.end();
|
||||
});
|
||||
exports.default = router;
|
||||
//# sourceMappingURL=auth.company.routes.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.company.routes.js","sourceRoot":"","sources":["../../../src/modules/auth/auth.company.routes.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAgC;AAChC,kDAA+C;AAC/C,gDAA4C;AAC5C,iEAA4D;AAC5D,gEAAiD;AAEjD,MAAM,MAAM,GAAG,IAAA,gBAAM,GAAE,CAAA;AAEvB,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;IAC9C,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,IAAA,oBAAS,EAAC,0CAAmB,EAAE,GAAG,CAAC,CAAA;QAChD,IAAA,iBAAO,EAAC,GAAG,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAA;IAC1C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAAC,CAAC;AAC7B,CAAC,CAAC,CAAA;AAEF,MAAM,CAAC,IAAI,CAAC,kBAAkB,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;IAC5C,OAAO,CAAC,sBAAsB,EAAE,CAAA;IAChC,GAAG,CAAC,GAAG,EAAE,CAAA;AACX,CAAC,CAAC,CAAA;AAEF,MAAM,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;IACzC,OAAO,CAAC,mBAAmB,EAAE,CAAA;IAC7B,GAAG,CAAC,GAAG,EAAE,CAAA;AACX,CAAC,CAAC,CAAA;AAEF,kBAAe,MAAM,CAAA"}
|
||||
@@ -0,0 +1,108 @@
|
||||
import { z } from 'zod';
|
||||
export declare const companySignupSchema: z.ZodObject<{
|
||||
firstName: z.ZodString;
|
||||
lastName: z.ZodString;
|
||||
email: z.ZodString;
|
||||
password: z.ZodString;
|
||||
companyName: z.ZodString;
|
||||
legalName: z.ZodString;
|
||||
legalForm: z.ZodString;
|
||||
registrationNumber: z.ZodString;
|
||||
iceNumber: z.ZodString;
|
||||
taxId: z.ZodString;
|
||||
operatingLicenseNumber: z.ZodString;
|
||||
operatingLicenseIssuedAt: z.ZodString;
|
||||
operatingLicenseIssuedBy: z.ZodString;
|
||||
streetAddress: z.ZodString;
|
||||
city: z.ZodString;
|
||||
country: z.ZodString;
|
||||
zipCode: z.ZodString;
|
||||
companyPhone: z.ZodString;
|
||||
companyEmail: z.ZodString;
|
||||
fax: z.ZodOptional<z.ZodString>;
|
||||
yearsActive: z.ZodString;
|
||||
representativeName: z.ZodOptional<z.ZodString>;
|
||||
representativeTitle: z.ZodOptional<z.ZodString>;
|
||||
responsibleName: z.ZodString;
|
||||
responsibleRole: z.ZodString;
|
||||
responsibleIdentityNumber: z.ZodString;
|
||||
responsibleQualification: z.ZodOptional<z.ZodString>;
|
||||
responsiblePhone: z.ZodString;
|
||||
responsibleEmail: z.ZodString;
|
||||
preferredLanguage: z.ZodDefault<z.ZodEnum<["en", "fr", "ar"]>>;
|
||||
plan: z.ZodEnum<["STARTER", "GROWTH", "PRO"]>;
|
||||
billingPeriod: z.ZodEnum<["MONTHLY", "ANNUAL"]>;
|
||||
currency: z.ZodLiteral<"MAD">;
|
||||
paymentProvider: z.ZodEnum<["AMANPAY", "PAYPAL"]>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
email: string;
|
||||
currency: "MAD";
|
||||
password: string;
|
||||
companyName: string;
|
||||
legalName: string;
|
||||
legalForm: string;
|
||||
registrationNumber: string;
|
||||
iceNumber: string;
|
||||
taxId: string;
|
||||
operatingLicenseNumber: string;
|
||||
operatingLicenseIssuedAt: string;
|
||||
operatingLicenseIssuedBy: string;
|
||||
streetAddress: string;
|
||||
city: string;
|
||||
country: string;
|
||||
zipCode: string;
|
||||
companyPhone: string;
|
||||
companyEmail: string;
|
||||
yearsActive: string;
|
||||
responsibleName: string;
|
||||
responsibleRole: string;
|
||||
responsibleIdentityNumber: string;
|
||||
responsiblePhone: string;
|
||||
responsibleEmail: string;
|
||||
preferredLanguage: "en" | "fr" | "ar";
|
||||
plan: "STARTER" | "GROWTH" | "PRO";
|
||||
billingPeriod: "MONTHLY" | "ANNUAL";
|
||||
paymentProvider: "AMANPAY" | "PAYPAL";
|
||||
fax?: string | undefined;
|
||||
representativeName?: string | undefined;
|
||||
representativeTitle?: string | undefined;
|
||||
responsibleQualification?: string | undefined;
|
||||
}, {
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
email: string;
|
||||
currency: "MAD";
|
||||
password: string;
|
||||
companyName: string;
|
||||
legalName: string;
|
||||
legalForm: string;
|
||||
registrationNumber: string;
|
||||
iceNumber: string;
|
||||
taxId: string;
|
||||
operatingLicenseNumber: string;
|
||||
operatingLicenseIssuedAt: string;
|
||||
operatingLicenseIssuedBy: string;
|
||||
streetAddress: string;
|
||||
city: string;
|
||||
country: string;
|
||||
zipCode: string;
|
||||
companyPhone: string;
|
||||
companyEmail: string;
|
||||
yearsActive: string;
|
||||
responsibleName: string;
|
||||
responsibleRole: string;
|
||||
responsibleIdentityNumber: string;
|
||||
responsiblePhone: string;
|
||||
responsibleEmail: string;
|
||||
plan: "STARTER" | "GROWTH" | "PRO";
|
||||
billingPeriod: "MONTHLY" | "ANNUAL";
|
||||
paymentProvider: "AMANPAY" | "PAYPAL";
|
||||
fax?: string | undefined;
|
||||
representativeName?: string | undefined;
|
||||
representativeTitle?: string | undefined;
|
||||
responsibleQualification?: string | undefined;
|
||||
preferredLanguage?: "en" | "fr" | "ar" | undefined;
|
||||
}>;
|
||||
//# sourceMappingURL=auth.company.schemas.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.company.schemas.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/auth.company.schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmC9B,CAAA"}
|
||||
@@ -0,0 +1,41 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.companySignupSchema = void 0;
|
||||
const zod_1 = require("zod");
|
||||
exports.companySignupSchema = zod_1.z.object({
|
||||
firstName: zod_1.z.string().min(1).max(80),
|
||||
lastName: zod_1.z.string().min(1).max(80),
|
||||
email: zod_1.z.string().email(),
|
||||
password: zod_1.z.string().min(8).max(128),
|
||||
companyName: zod_1.z.string().min(2).max(120),
|
||||
legalName: zod_1.z.string().min(2).max(160),
|
||||
legalForm: zod_1.z.string().min(1).max(80),
|
||||
registrationNumber: zod_1.z.string().min(1).max(120),
|
||||
iceNumber: zod_1.z.string().min(1).max(120),
|
||||
taxId: zod_1.z.string().min(1).max(120),
|
||||
operatingLicenseNumber: zod_1.z.string().min(1).max(120),
|
||||
operatingLicenseIssuedAt: zod_1.z.string().min(1).max(40),
|
||||
operatingLicenseIssuedBy: zod_1.z.string().min(1).max(160),
|
||||
streetAddress: zod_1.z.string().min(1).max(200),
|
||||
city: zod_1.z.string().min(1).max(120),
|
||||
country: zod_1.z.string().min(1).max(120),
|
||||
zipCode: zod_1.z.string().min(1).max(40),
|
||||
companyPhone: zod_1.z.string().min(1).max(80),
|
||||
companyEmail: zod_1.z.string().email(),
|
||||
fax: zod_1.z.string().max(80).optional(),
|
||||
yearsActive: zod_1.z.string().min(1).max(80),
|
||||
representativeName: zod_1.z.string().max(160).optional(),
|
||||
representativeTitle: zod_1.z.string().max(120).optional(),
|
||||
responsibleName: zod_1.z.string().min(1).max(160),
|
||||
responsibleRole: zod_1.z.string().min(1).max(120),
|
||||
responsibleIdentityNumber: zod_1.z.string().min(1).max(120),
|
||||
responsibleQualification: zod_1.z.string().max(200).optional(),
|
||||
responsiblePhone: zod_1.z.string().min(1).max(80),
|
||||
responsibleEmail: zod_1.z.string().email(),
|
||||
preferredLanguage: zod_1.z.enum(['en', 'fr', 'ar']).default('en'),
|
||||
plan: zod_1.z.enum(['STARTER', 'GROWTH', 'PRO']),
|
||||
billingPeriod: zod_1.z.enum(['MONTHLY', 'ANNUAL']),
|
||||
currency: zod_1.z.literal('MAD'),
|
||||
paymentProvider: zod_1.z.enum(['AMANPAY', 'PAYPAL']),
|
||||
});
|
||||
//# sourceMappingURL=auth.company.schemas.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.company.schemas.js","sourceRoot":"","sources":["../../../src/modules/auth/auth.company.schemas.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AAEV,QAAA,mBAAmB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC1C,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;IACpC,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC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,CAAC,QAAQ,EAAE;IACxD,gBAAgB,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;IAC3C,gBAAgB,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE;IACpC,iBAAiB,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;IAC3D,IAAI,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC1C,aAAa,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAC5C,QAAQ,EAAE,OAAC,CAAC,OAAO,CAAC,KAAK,CAAC;IAC1B,eAAe,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;CAC/C,CAAC,CAAA"}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { companySignupSchema } from './auth.company.schemas';
|
||||
import type { output } from 'zod';
|
||||
type CompanySignupInput = output<typeof companySignupSchema>;
|
||||
export declare function signup(body: CompanySignupInput): Promise<{
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
slug: string;
|
||||
invitationId: null;
|
||||
trialEndsAt: string;
|
||||
nextStep: string;
|
||||
emailDelivery: {};
|
||||
}>;
|
||||
export declare function completeSignupDisabled(): void;
|
||||
export declare function verifyEmailDisabled(): void;
|
||||
export {};
|
||||
//# sourceMappingURL=auth.company.service.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.company.service.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/auth.company.service.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,CAAA;AAEjC,KAAK,kBAAkB,GAAG,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAA;AAmB5D,wBAAsB,MAAM,CAAC,IAAI,EAAE,kBAAkB;;;;;;;;GAiFpD;AAED,wBAAgB,sBAAsB,SAErC;AAED,wBAAgB,mBAAmB,SAElC"}
|
||||
+145
@@ -0,0 +1,145 @@
|
||||
"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 __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 __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.signup = signup;
|
||||
exports.completeSignupDisabled = completeSignupDisabled;
|
||||
exports.verifyEmailDisabled = verifyEmailDisabled;
|
||||
const bcryptjs_1 = __importDefault(require("bcryptjs"));
|
||||
const errors_1 = require("../../http/errors");
|
||||
const prisma_1 = require("../../lib/prisma");
|
||||
const notificationService_1 = require("../../services/notificationService");
|
||||
const notificationLocalizationService_1 = require("../../services/notificationLocalizationService");
|
||||
const auth_presenter_1 = require("./auth.presenter");
|
||||
const repo = __importStar(require("./auth.company.repo"));
|
||||
const TRIAL_PERIOD_DAYS = 90;
|
||||
function slugify(value) {
|
||||
return value.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 50) || 'company';
|
||||
}
|
||||
async function generateUniqueSlug(baseName) {
|
||||
const base = slugify(baseName);
|
||||
for (let attempt = 0; attempt < 25; attempt++) {
|
||||
const slug = attempt === 0 ? base : `${base}-${attempt + 1}`;
|
||||
const existing = await repo.findCompanyBySlug(slug);
|
||||
if (!existing)
|
||||
return slug;
|
||||
}
|
||||
return `${base}-${Date.now().toString(36)}`;
|
||||
}
|
||||
async function signup(body) {
|
||||
if (await repo.findCompanyByEmail(body.companyEmail)) {
|
||||
throw new errors_1.AppError('A company account with this contact email already exists', 409, 'company_email_taken');
|
||||
}
|
||||
if (await repo.findEmployeeByEmail(body.email)) {
|
||||
throw new errors_1.AppError('An employee account with this owner email already exists', 409, 'owner_email_taken');
|
||||
}
|
||||
const slug = await generateUniqueSlug(body.companyName);
|
||||
const now = new Date();
|
||||
const trialEndAt = new Date(now.getTime() + TRIAL_PERIOD_DAYS * 24 * 60 * 60 * 1000);
|
||||
const passwordHash = await bcryptjs_1.default.hash(body.password, 12);
|
||||
const result = await prisma_1.prisma.$transaction((tx) => repo.createCompanySignup(tx, {
|
||||
companyName: body.companyName,
|
||||
legalName: body.legalName,
|
||||
slug,
|
||||
ownerEmail: body.email,
|
||||
companyEmail: body.companyEmail,
|
||||
companyPhone: body.companyPhone,
|
||||
streetAddress: body.streetAddress,
|
||||
city: body.city,
|
||||
country: body.country,
|
||||
zipCode: body.zipCode,
|
||||
legalForm: body.legalForm,
|
||||
managerName: `${body.firstName} ${body.lastName}`.trim(),
|
||||
iceNumber: body.iceNumber,
|
||||
taxId: body.taxId,
|
||||
operatingLicenseNumber: body.operatingLicenseNumber,
|
||||
operatingLicenseIssuedAt: body.operatingLicenseIssuedAt,
|
||||
operatingLicenseIssuedBy: body.operatingLicenseIssuedBy,
|
||||
fax: body.fax,
|
||||
yearsActive: body.yearsActive,
|
||||
representativeName: body.representativeName,
|
||||
representativeTitle: body.representativeTitle,
|
||||
responsibleName: body.responsibleName,
|
||||
responsibleRole: body.responsibleRole,
|
||||
responsibleIdentityNumber: body.responsibleIdentityNumber,
|
||||
responsibleQualification: body.responsibleQualification,
|
||||
responsiblePhone: body.responsiblePhone,
|
||||
responsibleEmail: body.responsibleEmail,
|
||||
currency: body.currency,
|
||||
registrationNumber: body.registrationNumber,
|
||||
plan: body.plan,
|
||||
billingPeriod: body.billingPeriod,
|
||||
preferredLanguage: body.preferredLanguage,
|
||||
firstName: body.firstName,
|
||||
lastName: body.lastName,
|
||||
passwordHash,
|
||||
now,
|
||||
trialEndAt,
|
||||
}));
|
||||
const lang = (0, notificationLocalizationService_1.coerceNotificationLocale)(body.preferredLanguage);
|
||||
const emailResult = await (0, notificationService_1.sendNotification)({
|
||||
type: 'ACCOUNT_CREATED',
|
||||
companyId: result.company.id,
|
||||
employeeId: result.employee.id,
|
||||
email: body.email,
|
||||
channels: ['EMAIL', 'IN_APP'],
|
||||
locale: lang,
|
||||
templateKey: 'account.created',
|
||||
templateVariables: {
|
||||
firstName: body.firstName,
|
||||
companyName: body.companyName,
|
||||
planName: (0, notificationLocalizationService_1.localizePlanName)(body.plan, lang),
|
||||
billingPeriodLabel: (0, notificationLocalizationService_1.localizeBillingPeriod)(body.billingPeriod, lang),
|
||||
currency: body.currency,
|
||||
paymentProvider: body.paymentProvider,
|
||||
trialEndDate: trialEndAt,
|
||||
},
|
||||
}).catch(() => []);
|
||||
const emailDelivery = emailResult.find((entry) => entry.channel === 'EMAIL');
|
||||
return (0, auth_presenter_1.presentCompanySignup)({
|
||||
company: result.company,
|
||||
trialEndAt,
|
||||
emailDelivery,
|
||||
});
|
||||
}
|
||||
function completeSignupDisabled() {
|
||||
throw new errors_1.AppError('Clerk-based signup has been removed. Use /auth/company/signup instead.', 410, 'disabled');
|
||||
}
|
||||
function verifyEmailDisabled() {
|
||||
throw new errors_1.AppError('Email verification resend via Clerk has been removed from this project.', 410, 'disabled');
|
||||
}
|
||||
//# sourceMappingURL=auth.company.service.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.company.service.js","sourceRoot":"","sources":["../../../src/modules/auth/auth.company.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,wBAiFC;AAED,wDAEC;AAED,kDAEC;AA1HD,wDAA6B;AAC7B,8CAA4C;AAC5C,6CAAyC;AACzC,4EAAqE;AACrE,oGAIuD;AACvD,qDAAuD;AACvD,0DAA2C;AAK3C,MAAM,iBAAiB,GAAG,EAAE,CAAA;AAE5B,SAAS,OAAO,CAAC,KAAa;IAC5B,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,SAAS,CAAA;AAC1G,CAAC;AAED,KAAK,UAAU,kBAAkB,CAAC,QAAgB;IAChD,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;IAE9B,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,GAAG,EAAE,EAAE,OAAO,EAAE,EAAE,CAAC;QAC9C,MAAM,IAAI,GAAG,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG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C/G,CAAC;AAED,SAAgB,mBAAmB;IACjC,MAAM,IAAI,iBAAQ,CAAC,yEAAyE,EAAE,GAAG,EAAE,UAAU,CAAC,CAAA;AAChH,CAAC"}
|
||||
@@ -0,0 +1,9 @@
|
||||
export declare function findEmployeeWithCompanyById(id: string): any;
|
||||
export declare function findEmployeeById(id: string): any;
|
||||
export declare function findEmployeeWithCompanyByEmail(email: string): any;
|
||||
export declare function findActiveEmployeeByEmail(email: string): any;
|
||||
export declare function setPasswordResetToken(id: string, passwordResetToken: string, passwordResetExpiresAt: Date): any;
|
||||
export declare function updatePreferredLanguage(id: string, preferredLanguage: 'en' | 'fr' | 'ar'): any;
|
||||
export declare function findEmployeeByResetToken(token: string): any;
|
||||
export declare function resetPassword(id: string, passwordHash: string): any;
|
||||
//# sourceMappingURL=auth.employee.repo.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.employee.repo.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/auth.employee.repo.ts"],"names":[],"mappings":"AAEA,wBAAgB,2BAA2B,CAAC,EAAE,EAAE,MAAM,OAKrD;AAED,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,OAI1C;AAED,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,MAAM,OAU3D;AAED,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,OAUtD;AAED,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,EAAE,sBAAsB,EAAE,IAAI,OAKzG;AAED,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,MAAM,EAAE,iBAAiB,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,OAKxF;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,OAOrD;AAED,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,OAS7D"}
|
||||
@@ -0,0 +1,75 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.findEmployeeWithCompanyById = findEmployeeWithCompanyById;
|
||||
exports.findEmployeeById = findEmployeeById;
|
||||
exports.findEmployeeWithCompanyByEmail = findEmployeeWithCompanyByEmail;
|
||||
exports.findActiveEmployeeByEmail = findActiveEmployeeByEmail;
|
||||
exports.setPasswordResetToken = setPasswordResetToken;
|
||||
exports.updatePreferredLanguage = updatePreferredLanguage;
|
||||
exports.findEmployeeByResetToken = findEmployeeByResetToken;
|
||||
exports.resetPassword = resetPassword;
|
||||
const prisma_1 = require("../../lib/prisma");
|
||||
function findEmployeeWithCompanyById(id) {
|
||||
return prisma_1.prisma.employee.findUnique({
|
||||
where: { id },
|
||||
include: { company: true },
|
||||
});
|
||||
}
|
||||
function findEmployeeById(id) {
|
||||
return prisma_1.prisma.employee.findUnique({
|
||||
where: { id },
|
||||
});
|
||||
}
|
||||
function findEmployeeWithCompanyByEmail(email) {
|
||||
return prisma_1.prisma.employee.findFirst({
|
||||
where: {
|
||||
email: {
|
||||
equals: email,
|
||||
mode: 'insensitive',
|
||||
},
|
||||
},
|
||||
include: { company: true },
|
||||
});
|
||||
}
|
||||
function findActiveEmployeeByEmail(email) {
|
||||
return prisma_1.prisma.employee.findFirst({
|
||||
where: {
|
||||
email: {
|
||||
equals: email,
|
||||
mode: 'insensitive',
|
||||
},
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
function setPasswordResetToken(id, passwordResetToken, passwordResetExpiresAt) {
|
||||
return prisma_1.prisma.employee.update({
|
||||
where: { id },
|
||||
data: { passwordResetToken, passwordResetExpiresAt },
|
||||
});
|
||||
}
|
||||
function updatePreferredLanguage(id, preferredLanguage) {
|
||||
return prisma_1.prisma.employee.update({
|
||||
where: { id },
|
||||
data: { preferredLanguage },
|
||||
});
|
||||
}
|
||||
function findEmployeeByResetToken(token) {
|
||||
return prisma_1.prisma.employee.findFirst({
|
||||
where: {
|
||||
passwordResetToken: token,
|
||||
passwordResetExpiresAt: { gt: new Date() },
|
||||
},
|
||||
});
|
||||
}
|
||||
function resetPassword(id, passwordHash) {
|
||||
return prisma_1.prisma.employee.update({
|
||||
where: { id },
|
||||
data: {
|
||||
passwordHash,
|
||||
passwordResetToken: null,
|
||||
passwordResetExpiresAt: null,
|
||||
},
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=auth.employee.repo.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.employee.repo.js","sourceRoot":"","sources":["../../../src/modules/auth/auth.employee.repo.ts"],"names":[],"mappings":";;AAEA,kEAKC;AAED,4CAIC;AAED,wEAUC;AAED,8DAUC;AAED,sDAKC;AAED,0DAKC;AAED,4DAOC;AAED,sCASC;AAvED,6CAAyC;AAEzC,SAAgB,2BAA2B,CAAC,EAAU;IACpD,OAAO,eAAM,CAAC,QAAQ,CAAC,UAAU,CAAC;QAChC,KAAK,EAAE,EAAE,EAAE,EAAE;QACb,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;KAC3B,CAAC,CAAA;AACJ,CAAC;AAED,SAAgB,gBAAgB,CAAC,EAAU;IACzC,OAAO,eAAM,CAAC,QAAQ,CAAC,UAAU,CAAC;QAChC,KAAK,EAAE,EAAE,EAAE,EAAE;KACd,CAAC,CAAA;AACJ,CAAC;AAED,SAAgB,8BAA8B,CAAC,KAAa;IAC1D,OAAO,eAAM,CAAC,QAAQ,CAAC,SAAS,CAAC;QAC/B,KAAK,EAAE;YACL,KAAK,EAAE;gBACL,MAAM,EAAE,KAAK;gBACb,IAAI,EAAE,aAAa;aACpB;SACF;QACD,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;KAC3B,CAAC,CAAA;AACJ,CAAC;AAED,SAAgB,yBAAyB,CAAC,KAAa;IACrD,OAAO,eAAM,CAAC,QAAQ,CAAC,SAAS,CAAC;QAC/B,KAAK,EAAE;YACL,KAAK,EAAE;gBACL,MAAM,EAAE,KAAK;gBACb,IAAI,EAAE,aAAa;aACpB;YACD,QAAQ,EAAE,IAAI;SACf;KACF,CAAC,CAAA;AACJ,CAAC;AAED,SAAgB,qBAAqB,CAAC,EAAU,EAAE,kBAA0B,EAAE,sBAA4B;IACxG,OAAO,eAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;QAC5B,KAAK,EAAE,EAAE,EAAE,EAAE;QACb,IAAI,EAAE,EAAE,kBAAkB,EAAE,sBAAsB,EAAE;KACrD,CAAC,CAAA;AACJ,CAAC;AAED,SAAgB,uBAAuB,CAAC,EAAU,EAAE,iBAAqC;IACvF,OAAO,eAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;QAC5B,KAAK,EAAE,EAAE,EAAE,EAAE;QACb,IAAI,EAAE,EAAE,iBAAiB,EAAE;KAC5B,CAAC,CAAA;AACJ,CAAC;AAED,SAAgB,wBAAwB,CAAC,KAAa;IACpD,OAAO,eAAM,CAAC,QAAQ,CAAC,SAAS,CAAC;QAC/B,KAAK,EAAE;YACL,kBAAkB,EAAE,KAAK;YACzB,sBAAsB,EAAE,EAAE,EAAE,EAAE,IAAI,IAAI,EAAE,EAAE;SAC3C;KACF,CAAC,CAAA;AACJ,CAAC;AAED,SAAgB,aAAa,CAAC,EAAU,EAAE,YAAoB;IAC5D,OAAO,eAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;QAC5B,KAAK,EAAE,EAAE,EAAE,EAAE;QACb,IAAI,EAAE;YACJ,YAAY;YACZ,kBAAkB,EAAE,IAAI;YACxB,sBAAsB,EAAE,IAAI;SAC7B;KACF,CAAC,CAAA;AACJ,CAAC"}
|
||||
@@ -0,0 +1,3 @@
|
||||
declare const router: import("express-serve-static-core").Router;
|
||||
export default router;
|
||||
//# sourceMappingURL=auth.employee.routes.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.employee.routes.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/auth.employee.routes.ts"],"names":[],"mappings":"AAcA,QAAA,MAAM,MAAM,4CAAW,CAAA;AAiDvB,eAAe,MAAM,CAAA"}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
"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 __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;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const express_1 = require("express");
|
||||
const requireCompanyAuth_1 = require("../../middleware/requireCompanyAuth");
|
||||
const validate_1 = require("../../http/validate");
|
||||
const respond_1 = require("../../http/respond");
|
||||
const sessionCookies_1 = require("../../security/sessionCookies");
|
||||
const menu_service_1 = require("../menu/menu.service");
|
||||
const auth_employee_schemas_1 = require("./auth.employee.schemas");
|
||||
const service = __importStar(require("./auth.employee.service"));
|
||||
const router = (0, express_1.Router)();
|
||||
router.get('/me', requireCompanyAuth_1.requireCompanyAuth, async (req, res, next) => {
|
||||
try {
|
||||
(0, respond_1.ok)(res, await service.getMe(req.employee.id));
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
router.get('/menu', requireCompanyAuth_1.requireCompanyAuth, async (req, res, next) => {
|
||||
try {
|
||||
(0, respond_1.ok)(res, await (0, menu_service_1.getEmployeeMenu)(req.employee.id));
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
router.post('/login', async (req, res, next) => {
|
||||
try {
|
||||
const body = (0, validate_1.parseBody)(auth_employee_schemas_1.employeeLoginSchema, req);
|
||||
const result = await service.login(body);
|
||||
if ('token' in result)
|
||||
(0, sessionCookies_1.setSessionCookie)(res, 'employee', result.token, 8 * 60 * 60 * 1000);
|
||||
(0, respond_1.ok)(res, result);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
router.post('/logout', (_req, res) => {
|
||||
(0, sessionCookies_1.clearSessionCookie)(res, 'employee');
|
||||
(0, respond_1.ok)(res, { success: true });
|
||||
});
|
||||
router.post('/forgot-password', async (req, res, next) => {
|
||||
try {
|
||||
const { email } = (0, validate_1.parseBody)(auth_employee_schemas_1.employeeForgotPasswordSchema, req);
|
||||
(0, respond_1.ok)(res, await service.forgotPassword(email));
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
router.patch('/me/language', requireCompanyAuth_1.requireCompanyAuth, async (req, res, next) => {
|
||||
try {
|
||||
const { language } = (0, validate_1.parseBody)(auth_employee_schemas_1.employeeLanguageSchema, req);
|
||||
(0, respond_1.ok)(res, await service.updateLanguage(req.employee.id, language));
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
router.post('/reset-password', async (req, res, next) => {
|
||||
try {
|
||||
const { token, password } = (0, validate_1.parseBody)(auth_employee_schemas_1.employeeResetPasswordSchema, req);
|
||||
(0, respond_1.ok)(res, await service.resetPassword(token, password));
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
exports.default = router;
|
||||
//# sourceMappingURL=auth.employee.routes.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.employee.routes.js","sourceRoot":"","sources":["../../../src/modules/auth/auth.employee.routes.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAgC;AAChC,4EAAwE;AACxE,kDAA+C;AAC/C,gDAAuC;AACvC,kEAAoF;AACpF,uDAAsD;AACtD,mEAKgC;AAChC,iEAAkD;AAElD,MAAM,MAAM,GAAG,IAAA,gBAAM,GAAE,CAAA;AAEvB,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,uCAAkB,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;IAC7D,IAAI,CAAC;QACH,IAAA,YAAE,EAAC,GAAG,EAAE,MAAM,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAA;IAC/C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAAC,CAAC;AAC7B,CAAC,CAAC,CAAA;AAEF,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,uCAAkB,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;IAC/D,IAAI,CAAC;QACH,IAAA,YAAE,EAAC,GAAG,EAAE,MAAM,IAAA,8BAAe,EAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAA;IACjD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAAC,CAAC;AAC7B,CAAC,CAAC,CAAA;AAEF,MAAM,CAAC,IAAI,CA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C,KAAK,CAAC,cAAc,EAAE,uCAAkB,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;IACxE,IAAI,CAAC;QACH,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAA,oBAAS,EAAC,8CAAsB,EAAE,GAAG,CAAC,CAAA;QAC3D,IAAA,YAAE,EAAC,GAAG,EAAE,MAAM,OAAO,CAAC,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAA;IAClE,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAAC,CAAC;AAC7B,CAAC,CAAC,CAAA;AAEF,MAAM,CAAC,IAAI,CAAC,iBAAiB,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;IACtD,IAAI,CAAC;QACH,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAA,oBAAS,EAAC,mDAA2B,EAAE,GAAG,CAAC,CAAA;QACvE,IAAA,YAAE,EAAC,GAAG,EAAE,MAAM,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAA;IACvD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAAC,CAAC;AAC7B,CAAC,CAAC,CAAA;AAEF,kBAAe,MAAM,CAAA"}
|
||||
@@ -0,0 +1,36 @@
|
||||
import { z } from 'zod';
|
||||
export declare const employeeLoginSchema: z.ZodObject<{
|
||||
email: z.ZodString;
|
||||
password: z.ZodString;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
email: string;
|
||||
password: string;
|
||||
}, {
|
||||
email: string;
|
||||
password: string;
|
||||
}>;
|
||||
export declare const employeeForgotPasswordSchema: z.ZodObject<{
|
||||
email: z.ZodString;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
email: string;
|
||||
}, {
|
||||
email: string;
|
||||
}>;
|
||||
export declare const employeeLanguageSchema: z.ZodObject<{
|
||||
language: z.ZodEnum<["en", "fr", "ar"]>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
language: "en" | "fr" | "ar";
|
||||
}, {
|
||||
language: "en" | "fr" | "ar";
|
||||
}>;
|
||||
export declare const employeeResetPasswordSchema: z.ZodObject<{
|
||||
token: z.ZodString;
|
||||
password: z.ZodString;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
password: string;
|
||||
token: string;
|
||||
}, {
|
||||
password: string;
|
||||
token: string;
|
||||
}>;
|
||||
//# sourceMappingURL=auth.employee.schemas.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.employee.schemas.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/auth.employee.schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,eAAO,MAAM,mBAAmB;;;;;;;;;EAG9B,CAAA;AAEF,eAAO,MAAM,4BAA4B;;;;;;EAEvC,CAAA;AAEF,eAAO,MAAM,sBAAsB;;;;;;EAEjC,CAAA;AAEF,eAAO,MAAM,2BAA2B;;;;;;;;;EAGtC,CAAA"}
|
||||
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.employeeResetPasswordSchema = exports.employeeLanguageSchema = exports.employeeForgotPasswordSchema = exports.employeeLoginSchema = void 0;
|
||||
const zod_1 = require("zod");
|
||||
exports.employeeLoginSchema = zod_1.z.object({
|
||||
email: zod_1.z.string().email().max(255).trim().toLowerCase(),
|
||||
password: zod_1.z.string().max(128),
|
||||
});
|
||||
exports.employeeForgotPasswordSchema = zod_1.z.object({
|
||||
email: zod_1.z.string().email().max(255).trim().toLowerCase(),
|
||||
});
|
||||
exports.employeeLanguageSchema = zod_1.z.object({
|
||||
language: zod_1.z.enum(['en', 'fr', 'ar']),
|
||||
});
|
||||
exports.employeeResetPasswordSchema = zod_1.z.object({
|
||||
token: zod_1.z.string().min(1),
|
||||
password: zod_1.z.string().min(8).max(128),
|
||||
});
|
||||
//# sourceMappingURL=auth.employee.schemas.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.employee.schemas.js","sourceRoot":"","sources":["../../../src/modules/auth/auth.employee.schemas.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AAEV,QAAA,mBAAmB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC1C,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE;IACvD,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC;CAC9B,CAAC,CAAA;AAEW,QAAA,4BAA4B,GAAG,OAAC,CAAC,MAAM,CAAC;IACnD,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE;CACxD,CAAC,CAAA;AAEW,QAAA,sBAAsB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC7C,QAAQ,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;CACrC,CAAC,CAAA;AAEW,QAAA,2BAA2B,GAAG,OAAC,CAAC,MAAM,CAAC;IAClD,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACxB,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;CACrC,CAAC,CAAA"}
|
||||
@@ -0,0 +1,67 @@
|
||||
import { employeeLanguageSchema, employeeLoginSchema } from './auth.employee.schemas';
|
||||
import type { output } from 'zod';
|
||||
type EmployeeLoginInput = output<typeof employeeLoginSchema>;
|
||||
type EmployeeLanguageInput = output<typeof employeeLanguageSchema>;
|
||||
export declare function getMe(employeeId: string): Promise<{
|
||||
employee: {
|
||||
id: string;
|
||||
email: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
role: string;
|
||||
preferredLanguage: string | null | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
companySlug: string;
|
||||
};
|
||||
} | {
|
||||
employee: {
|
||||
id: string;
|
||||
email: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
role: string;
|
||||
preferredLanguage: string | null | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
companySlug: string;
|
||||
};
|
||||
token: string;
|
||||
}>;
|
||||
export declare function login(body: EmployeeLoginInput): Promise<{
|
||||
employee: {
|
||||
id: string;
|
||||
email: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
role: string;
|
||||
preferredLanguage: string | null | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
companySlug: string;
|
||||
};
|
||||
} | {
|
||||
employee: {
|
||||
id: string;
|
||||
email: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
role: string;
|
||||
preferredLanguage: string | null | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
companySlug: string;
|
||||
};
|
||||
token: string;
|
||||
}>;
|
||||
export declare function forgotPassword(email: string): Promise<{
|
||||
message: string;
|
||||
}>;
|
||||
export declare function updateLanguage(employeeId: string, language: EmployeeLanguageInput['language']): Promise<{
|
||||
language: "en" | "fr" | "ar";
|
||||
}>;
|
||||
export declare function resetPassword(token: string, password: string): Promise<{
|
||||
message: string;
|
||||
}>;
|
||||
export {};
|
||||
//# sourceMappingURL=auth.employee.service.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.employee.service.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/auth.employee.service.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AACrF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,CAAA;AAIjC,KAAK,kBAAkB,GAAG,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAA;AAC5D,KAAK,qBAAqB,GAAG,MAAM,CAAC,OAAO,sBAAsB,CAAC,CAAA;AAuElE,wBAAsB,KAAK,CAAC,UAAU,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;GAQ7C;AAED,wBAAsB,KAAK,CAAC,IAAI,EAAE,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;GAiBnD;AAED,wBAAsB,cAAc,CAAC,KAAK,EAAE,MAAM;;GAwBjD;AAED,wBAAsB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,qBAAqB,CAAC,UAAU,CAAC;;GAGnG;AAuBD,wBAAsB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;;GASlE"}
|
||||
+180
@@ -0,0 +1,180 @@
|
||||
"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 __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 __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getMe = getMe;
|
||||
exports.login = login;
|
||||
exports.forgotPassword = forgotPassword;
|
||||
exports.updateLanguage = updateLanguage;
|
||||
exports.resetPassword = resetPassword;
|
||||
const bcryptjs_1 = __importDefault(require("bcryptjs"));
|
||||
const crypto_1 = __importDefault(require("crypto"));
|
||||
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
||||
const tokens_1 = require("../../security/tokens");
|
||||
const errors_1 = require("../../http/errors");
|
||||
const notificationService_1 = require("../../services/notificationService");
|
||||
const emailTranslations_1 = require("../../lib/emailTranslations");
|
||||
const auth_presenter_1 = require("./auth.presenter");
|
||||
const repo = __importStar(require("./auth.employee.repo"));
|
||||
const RESET_TOKEN_TTL_MINUTES = 60;
|
||||
function signEmployeeToken(employeeId) {
|
||||
return (0, tokens_1.signActorToken)(employeeId, 'employee', {
|
||||
expiresIn: (process.env.JWT_EXPIRY ?? '8h'),
|
||||
});
|
||||
}
|
||||
function getEmployeePasswordResetVersion(passwordHash) {
|
||||
return crypto_1.default
|
||||
.createHash('sha256')
|
||||
.update(`${process.env.JWT_SECRET}:${passwordHash ?? 'no-password-set'}`)
|
||||
.digest('hex');
|
||||
}
|
||||
function signEmployeePasswordResetToken(employeeId, passwordHash) {
|
||||
return jsonwebtoken_1.default.sign({
|
||||
sub: employeeId,
|
||||
type: 'employee_password_reset',
|
||||
pwdv: getEmployeePasswordResetVersion(passwordHash),
|
||||
}, process.env.JWT_SECRET, {
|
||||
algorithm: 'HS256',
|
||||
issuer: 'rentaldrivego-api',
|
||||
audience: 'employee_password_reset',
|
||||
expiresIn: `${RESET_TOKEN_TTL_MINUTES}m`,
|
||||
});
|
||||
}
|
||||
function verifyEmployeePasswordResetToken(token) {
|
||||
try {
|
||||
const payload = jsonwebtoken_1.default.verify(token, process.env.JWT_SECRET, {
|
||||
algorithms: ['HS256'],
|
||||
issuer: 'rentaldrivego-api',
|
||||
audience: 'employee_password_reset',
|
||||
});
|
||||
if (typeof payload.sub !== 'string' ||
|
||||
payload.type !== 'employee_password_reset' ||
|
||||
typeof payload.pwdv !== 'string') {
|
||||
return null;
|
||||
}
|
||||
return payload;
|
||||
}
|
||||
catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
function ensureDashboardBasePath(baseUrl) {
|
||||
try {
|
||||
const url = new URL(baseUrl);
|
||||
const pathname = url.pathname.replace(/\/$/, '');
|
||||
if (!pathname.endsWith('/dashboard'))
|
||||
url.pathname = `${pathname}/dashboard`;
|
||||
return url.toString().replace(/\/$/, '');
|
||||
}
|
||||
catch {
|
||||
const trimmed = baseUrl.replace(/\/$/, '');
|
||||
return trimmed.endsWith('/dashboard') ? trimmed : `${trimmed}/dashboard`;
|
||||
}
|
||||
}
|
||||
async function getMe(employeeId) {
|
||||
const employee = await repo.findEmployeeWithCompanyById(employeeId);
|
||||
if (!employee || !employee.isActive) {
|
||||
throw new errors_1.AppError('Employee account not found or inactive', 401, 'unauthenticated');
|
||||
}
|
||||
return (0, auth_presenter_1.presentEmployeeSession)(employee);
|
||||
}
|
||||
async function login(body) {
|
||||
const employee = await repo.findEmployeeWithCompanyByEmail(body.email);
|
||||
if (!employee || !employee.isActive) {
|
||||
throw new errors_1.AppError('Invalid email or password', 401, 'invalid_credentials');
|
||||
}
|
||||
if (!employee.passwordHash) {
|
||||
throw new errors_1.AppError('This account does not have a password yet. Use the invitation or reset email to set one first.', 401, 'password_not_set');
|
||||
}
|
||||
const validPassword = await bcryptjs_1.default.compare(body.password, employee.passwordHash);
|
||||
if (!validPassword) {
|
||||
throw new errors_1.AppError('Invalid email or password', 401, 'invalid_credentials');
|
||||
}
|
||||
return (0, auth_presenter_1.presentEmployeeSession)(employee, signEmployeeToken(employee.id));
|
||||
}
|
||||
async function forgotPassword(email) {
|
||||
const employee = await repo.findActiveEmployeeByEmail(email);
|
||||
if (employee) {
|
||||
const resetToken = signEmployeePasswordResetToken(employee.id, employee.passwordHash);
|
||||
const dashboardUrl = ensureDashboardBasePath(process.env.DASHBOARD_URL ?? process.env.NEXT_PUBLIC_DASHBOARD_URL ?? 'http://localhost:3000/dashboard');
|
||||
const resetUrl = `${dashboardUrl}/reset-password?token=${encodeURIComponent(resetToken)}`;
|
||||
const lang = employee.preferredLanguage ?? 'fr';
|
||||
await (0, notificationService_1.sendTransactionalEmail)({
|
||||
to: employee.email,
|
||||
subject: emailTranslations_1.resetPasswordEmail.subject(lang),
|
||||
html: emailTranslations_1.resetPasswordEmail.html(resetUrl, employee.firstName, RESET_TOKEN_TTL_MINUTES, lang),
|
||||
text: emailTranslations_1.resetPasswordEmail.text(resetUrl, employee.firstName, RESET_TOKEN_TTL_MINUTES, lang),
|
||||
}).catch((err) => {
|
||||
console.error('[ForgotPassword] Email delivery failed:', err?.message);
|
||||
console.error('[ForgotPassword] Provider config — resendKey present:', !!process.env.RESEND_API_KEY, '| smtpHost:', process.env.MAIL_HOST ?? 'not set');
|
||||
});
|
||||
}
|
||||
return { message: 'If that email is registered, a reset link has been sent.' };
|
||||
}
|
||||
async function updateLanguage(employeeId, language) {
|
||||
await repo.updatePreferredLanguage(employeeId, language);
|
||||
return { language };
|
||||
}
|
||||
async function findEmployeeFromResetToken(token) {
|
||||
try {
|
||||
const employee = await repo.findEmployeeByResetToken(token);
|
||||
if (employee)
|
||||
return employee;
|
||||
}
|
||||
catch (err) {
|
||||
console.error('[EmployeeResetPassword] Stored token lookup failed:', err?.message ?? String(err));
|
||||
}
|
||||
const payload = verifyEmployeePasswordResetToken(token);
|
||||
if (!payload)
|
||||
return null;
|
||||
const employee = await repo.findEmployeeById(payload.sub);
|
||||
if (!employee || !employee.isActive)
|
||||
return null;
|
||||
if (payload.pwdv !== getEmployeePasswordResetVersion(employee.passwordHash)) {
|
||||
return null;
|
||||
}
|
||||
return employee;
|
||||
}
|
||||
async function resetPassword(token, password) {
|
||||
const employee = await findEmployeeFromResetToken(token);
|
||||
if (!employee) {
|
||||
throw new errors_1.AppError('Reset link is invalid or has expired.', 400, 'invalid_token');
|
||||
}
|
||||
await repo.resetPassword(employee.id, await bcryptjs_1.default.hash(password, 12));
|
||||
return { message: 'Password updated successfully. You can now sign in.' };
|
||||
}
|
||||
//# sourceMappingURL=auth.employee.service.js.map
|
||||
File diff suppressed because one or more lines are too long
+98
@@ -0,0 +1,98 @@
|
||||
type EmployeeWithCompany = {
|
||||
id: string;
|
||||
email: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
role: string;
|
||||
preferredLanguage?: string | null;
|
||||
companyId: string;
|
||||
company: {
|
||||
name: string;
|
||||
slug: string;
|
||||
};
|
||||
};
|
||||
type CompanySignupResult = {
|
||||
company: {
|
||||
id: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
};
|
||||
trialEndAt: Date;
|
||||
emailDelivery?: unknown;
|
||||
};
|
||||
type RenterProfile = {
|
||||
id: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
email: string;
|
||||
phone: string | null;
|
||||
preferredLocale: string | null;
|
||||
preferredCurrency: string | null;
|
||||
emailVerified: boolean;
|
||||
savedCompanies: Array<{
|
||||
companyId: string;
|
||||
}>;
|
||||
};
|
||||
type SavedCompany = {
|
||||
id: string;
|
||||
brand: {
|
||||
displayName: string | null;
|
||||
subdomain: string | null;
|
||||
logoUrl: string | null;
|
||||
} | null;
|
||||
};
|
||||
export declare function presentEmployeeSession(employee: EmployeeWithCompany, token?: string): {
|
||||
employee: {
|
||||
id: string;
|
||||
email: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
role: string;
|
||||
preferredLanguage: string | null | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
companySlug: string;
|
||||
};
|
||||
} | {
|
||||
employee: {
|
||||
id: string;
|
||||
email: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
role: string;
|
||||
preferredLanguage: string | null | undefined;
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
companySlug: string;
|
||||
};
|
||||
token: string;
|
||||
};
|
||||
export declare function presentCompanySignup(result: CompanySignupResult): {
|
||||
companyId: string;
|
||||
companyName: string;
|
||||
slug: string;
|
||||
invitationId: null;
|
||||
trialEndsAt: string;
|
||||
nextStep: string;
|
||||
emailDelivery: {};
|
||||
};
|
||||
export declare function presentRenterProfile(renter: RenterProfile, companies: SavedCompany[]): {
|
||||
savedCompanies: {
|
||||
id: string;
|
||||
brand: {
|
||||
displayName: string | null;
|
||||
subdomain: string | null;
|
||||
logoUrl: string | null;
|
||||
} | null;
|
||||
}[];
|
||||
id: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
email: string;
|
||||
phone: string | null;
|
||||
preferredLocale: string | null;
|
||||
preferredCurrency: string | null;
|
||||
emailVerified: boolean;
|
||||
};
|
||||
export {};
|
||||
//# sourceMappingURL=auth.presenter.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.presenter.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/auth.presenter.ts"],"names":[],"mappings":"AAAA,KAAK,mBAAmB,GAAG;IACzB,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACjC,SAAS,E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,GAAG,IAAI;uBACf,MAAM,GAAG,IAAI;qBACf,MAAM,GAAG,IAAI;;;QAhBpB,MAAM;eACC,MAAM;cACP,MAAM;WACT,MAAM;WACN,MAAM,GAAG,IAAI;qBACH,MAAM,GAAG,IAAI;uBACX,MAAM,GAAG,IAAI;mBACjB,OAAO;EAqDvB"}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.presentEmployeeSession = presentEmployeeSession;
|
||||
exports.presentCompanySignup = presentCompanySignup;
|
||||
exports.presentRenterProfile = presentRenterProfile;
|
||||
function presentEmployeeSession(employee, token) {
|
||||
const data = {
|
||||
employee: {
|
||||
id: employee.id,
|
||||
email: employee.email,
|
||||
firstName: employee.firstName,
|
||||
lastName: employee.lastName,
|
||||
role: employee.role,
|
||||
preferredLanguage: employee.preferredLanguage,
|
||||
companyId: employee.companyId,
|
||||
companyName: employee.company.name,
|
||||
companySlug: employee.company.slug,
|
||||
},
|
||||
};
|
||||
return token ? { token, ...data } : data;
|
||||
}
|
||||
function presentCompanySignup(result) {
|
||||
return {
|
||||
companyId: result.company.id,
|
||||
companyName: result.company.name,
|
||||
slug: result.company.slug,
|
||||
invitationId: null,
|
||||
trialEndsAt: result.trialEndAt.toISOString(),
|
||||
nextStep: 'workspace_created',
|
||||
emailDelivery: result.emailDelivery ?? { attempted: false, success: false, error: null },
|
||||
};
|
||||
}
|
||||
function presentRenterProfile(renter, companies) {
|
||||
const companyMap = new Map(companies.map((company) => [company.id, company]));
|
||||
return {
|
||||
...renter,
|
||||
savedCompanies: renter.savedCompanies.map((savedCompany) => ({
|
||||
id: savedCompany.companyId,
|
||||
brand: companyMap.get(savedCompany.companyId)?.brand ?? null,
|
||||
})),
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=auth.presenter.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.presenter.js","sourceRoot":"","sources":["../../../src/modules/auth/auth.presenter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AAC,CAAC,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;IAE7E,OAAO;QACL,GAAG,MAAM;QACT,cAAc,EAAE,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;YAC3D,EAAE,EAAE,YAAY,CAAC,SAAS;YAC1B,KAAK,EAAE,UAAU,CAAC,GAAG,CAAC,YAAY,CAAC,SAAS,CAAC,EAAE,KAAK,IAAI,IAAI;SAC7D,CAAC,CAAC;KACJ,CAAA;AACH,CAAC"}
|
||||
@@ -0,0 +1,9 @@
|
||||
import type { output } from 'zod';
|
||||
import { renterUpdateSchema } from './auth.renter.schemas';
|
||||
type RenterUpdateInput = output<typeof renterUpdateSchema>;
|
||||
export declare function findRenterProfile(id: string): any;
|
||||
export declare function findSavedCompanies(companyIds: string[]): any;
|
||||
export declare function updateRenterProfile(id: string, data: RenterUpdateInput): any;
|
||||
export declare function updateRenterFcmToken(id: string, fcmToken: string): any;
|
||||
export {};
|
||||
//# sourceMappingURL=auth.renter.repo.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.renter.repo.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/auth.renter.repo.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,CAAA;AACjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAE1D,KAAK,iBAAiB,GAAG,MAAM,CAAC,OAAO,kBAAkB,CAAC,CAAA;AAE1D,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,MAAM,OAe3C;AAED,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,OAYtD;AAED,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB,OAKtE;AAED,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAKhE"}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.findRenterProfile = findRenterProfile;
|
||||
exports.findSavedCompanies = findSavedCompanies;
|
||||
exports.updateRenterProfile = updateRenterProfile;
|
||||
exports.updateRenterFcmToken = updateRenterFcmToken;
|
||||
const prisma_1 = require("../../lib/prisma");
|
||||
function findRenterProfile(id) {
|
||||
return prisma_1.prisma.renter.findUniqueOrThrow({
|
||||
where: { id },
|
||||
select: {
|
||||
id: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
email: true,
|
||||
phone: true,
|
||||
preferredLocale: true,
|
||||
preferredCurrency: true,
|
||||
emailVerified: true,
|
||||
savedCompanies: { select: { companyId: true } },
|
||||
},
|
||||
});
|
||||
}
|
||||
function findSavedCompanies(companyIds) {
|
||||
return companyIds.length === 0
|
||||
? Promise.resolve([])
|
||||
: prisma_1.prisma.company.findMany({
|
||||
where: { id: { in: companyIds } },
|
||||
select: {
|
||||
id: true,
|
||||
brand: {
|
||||
select: { displayName: true, subdomain: true, logoUrl: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
function updateRenterProfile(id, data) {
|
||||
return prisma_1.prisma.renter.update({
|
||||
where: { id },
|
||||
data,
|
||||
});
|
||||
}
|
||||
function updateRenterFcmToken(id, fcmToken) {
|
||||
return prisma_1.prisma.renter.update({
|
||||
where: { id },
|
||||
data: { fcmToken },
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=auth.renter.repo.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.renter.repo.js","sourceRoot":"","sources":["../../../src/modules/auth/auth.renter.repo.ts"],"names":[],"mappings":";;AAMA,8CAeC;AAED,gDAYC;AAED,kDAKC;AAED,oDAKC;AAjDD,6CAAyC;AAMzC,SAAgB,iBAAiB,CAAC,EAAU;IAC1C,OAAO,eAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC;QACrC,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export default router;
|
||||
//# sourceMappingURL=auth.renter.routes.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.renter.routes.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/auth.renter.routes.ts"],"names":[],"mappings":"AAOA,QAAA,MAAM,MAAM,4CAAW,CAAA;AAgCvB,eAAe,MAAM,CAAA"}
|
||||
@@ -0,0 +1,78 @@
|
||||
"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 __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;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const express_1 = require("express");
|
||||
const requireRenterAuth_1 = require("../../middleware/requireRenterAuth");
|
||||
const validate_1 = require("../../http/validate");
|
||||
const respond_1 = require("../../http/respond");
|
||||
const auth_renter_schemas_1 = require("./auth.renter.schemas");
|
||||
const service = __importStar(require("./auth.renter.service"));
|
||||
const router = (0, express_1.Router)();
|
||||
router.post('/signup', (_req, res) => {
|
||||
service.signupDisabled();
|
||||
res.end();
|
||||
});
|
||||
router.post('/login', (_req, res) => {
|
||||
service.loginDisabled();
|
||||
res.end();
|
||||
});
|
||||
router.get('/me', requireRenterAuth_1.requireRenterAuth, async (req, res, next) => {
|
||||
try {
|
||||
(0, respond_1.ok)(res, await service.getMe(req.renterId));
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
router.patch('/me', requireRenterAuth_1.requireRenterAuth, async (req, res, next) => {
|
||||
try {
|
||||
const body = (0, validate_1.parseBody)(auth_renter_schemas_1.renterUpdateSchema, req);
|
||||
(0, respond_1.ok)(res, await service.updateMe(req.renterId, body));
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
router.post('/me/fcm-token', requireRenterAuth_1.requireRenterAuth, async (req, res, next) => {
|
||||
try {
|
||||
const { fcmToken } = (0, validate_1.parseBody)(auth_renter_schemas_1.renterFcmTokenSchema, req);
|
||||
(0, respond_1.ok)(res, await service.updateFcmToken(req.renterId, fcmToken));
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
exports.default = router;
|
||||
//# sourceMappingURL=auth.renter.routes.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.renter.routes.js","sourceRoot":"","sources":["../../../src/modules/auth/auth.renter.routes.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAgC;AAChC,0EAAsE;AACtE,kDAA+C;AAC/C,gDAAuC;AACvC,+DAAgF;AAChF,+DAAgD;AAEhD,MAAM,MAAM,GAAG,IAAA,gBAAM,GAAE,CAAA;AAEvB,MAAM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E;IACvE,IAAI,CAAC;QACH,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAA,oBAAS,EAAC,0CAAoB,EAAE,GAAG,CAAC,CAAA;QACzD,IAAA,YAAE,EAAC,GAAG,EAAE,MAAM,OAAO,CAAC,cAAc,CAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAA;IAC/D,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAAC,CAAC;AAC7B,CAAC,CAAC,CAAA;AAEF,kBAAe,MAAM,CAAA"}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { z } from 'zod';
|
||||
export declare const renterUpdateSchema: z.ZodObject<{
|
||||
firstName: z.ZodOptional<z.ZodString>;
|
||||
lastName: z.ZodOptional<z.ZodString>;
|
||||
phone: z.ZodOptional<z.ZodString>;
|
||||
preferredLocale: z.ZodOptional<z.ZodEnum<["en", "fr", "ar"]>>;
|
||||
preferredCurrency: z.ZodOptional<z.ZodLiteral<"MAD">>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
firstName?: string | undefined;
|
||||
lastName?: string | undefined;
|
||||
phone?: string | undefined;
|
||||
preferredLocale?: "en" | "fr" | "ar" | undefined;
|
||||
preferredCurrency?: "MAD" | undefined;
|
||||
}, {
|
||||
firstName?: string | undefined;
|
||||
lastName?: string | undefined;
|
||||
phone?: string | undefined;
|
||||
preferredLocale?: "en" | "fr" | "ar" | undefined;
|
||||
preferredCurrency?: "MAD" | undefined;
|
||||
}>;
|
||||
export declare const renterFcmTokenSchema: z.ZodObject<{
|
||||
fcmToken: z.ZodString;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
fcmToken: string;
|
||||
}, {
|
||||
fcmToken: string;
|
||||
}>;
|
||||
//# sourceMappingURL=auth.renter.schemas.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.renter.schemas.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/auth.renter.schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;EAM7B,CAAA;AAEF,eAAO,MAAM,oBAAoB;;;;;;EAE/B,CAAA"}
|
||||
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.renterFcmTokenSchema = exports.renterUpdateSchema = void 0;
|
||||
const zod_1 = require("zod");
|
||||
exports.renterUpdateSchema = zod_1.z.object({
|
||||
firstName: zod_1.z.string().min(1).max(100).trim().optional(),
|
||||
lastName: zod_1.z.string().min(1).max(100).trim().optional(),
|
||||
phone: zod_1.z.string().max(30).trim().optional(),
|
||||
preferredLocale: zod_1.z.enum(['en', 'fr', 'ar']).optional(),
|
||||
preferredCurrency: zod_1.z.literal('MAD').optional(),
|
||||
});
|
||||
exports.renterFcmTokenSchema = zod_1.z.object({
|
||||
fcmToken: zod_1.z.string(),
|
||||
});
|
||||
//# sourceMappingURL=auth.renter.schemas.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.renter.schemas.js","sourceRoot":"","sources":["../../../src/modules/auth/auth.renter.schemas.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AAEV,QAAA,kBAAkB,GAAG,OAAC,CAAC,MAAM,CAAC;IACzC,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE;IACvD,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE;IACtD,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE;IAC3C,eAAe,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,QAAQ,EAAE;IACtD,iBAAiB,EAAE,OAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE;CAC/C,CAAC,CAAA;AAEW,QAAA,oBAAoB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3C,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE;CACrB,CAAC,CAAA"}
|
||||
@@ -0,0 +1,29 @@
|
||||
import type { output } from 'zod';
|
||||
import { renterUpdateSchema } from './auth.renter.schemas';
|
||||
type RenterUpdateInput = output<typeof renterUpdateSchema>;
|
||||
export declare function signupDisabled(): void;
|
||||
export declare function loginDisabled(): void;
|
||||
export declare function getMe(renterId: string): Promise<{
|
||||
savedCompanies: {
|
||||
id: string;
|
||||
brand: {
|
||||
displayName: string | null;
|
||||
subdomain: string | null;
|
||||
logoUrl: string | null;
|
||||
} | null;
|
||||
}[];
|
||||
id: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
email: string;
|
||||
phone: string | null;
|
||||
preferredLocale: string | null;
|
||||
preferredCurrency: string | null;
|
||||
emailVerified: boolean;
|
||||
}>;
|
||||
export declare function updateMe(renterId: string, body: RenterUpdateInput): any;
|
||||
export declare function updateFcmToken(renterId: string, fcmToken: string): Promise<{
|
||||
success: boolean;
|
||||
}>;
|
||||
export {};
|
||||
//# sourceMappingURL=auth.renter.service.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.renter.service.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/auth.renter.service.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,CAAA;AACjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAE1D,KAAK,iBAAiB,GAAG,MAAM,CAAC,OAAO,kBAAkB,CAAC,CAAA;AAE1D,wBAAgB,cAAc,SAE7B;AAED,wBAAgB,aAAa,SAE5B;AAED,wBAAsB,KAAK,CAAC,QAAQ,EAAE,MAAM;;;;;;;;;;;;;;;;;GAI3C;AAED,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB,OAEjE;AAED,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;;GAGtE"}
|
||||
@@ -0,0 +1,62 @@
|
||||
"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 __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;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.signupDisabled = signupDisabled;
|
||||
exports.loginDisabled = loginDisabled;
|
||||
exports.getMe = getMe;
|
||||
exports.updateMe = updateMe;
|
||||
exports.updateFcmToken = updateFcmToken;
|
||||
const errors_1 = require("../../http/errors");
|
||||
const auth_presenter_1 = require("./auth.presenter");
|
||||
const repo = __importStar(require("./auth.renter.repo"));
|
||||
function signupDisabled() {
|
||||
throw new errors_1.AppError('Renter account creation is disabled. Only company owners can sign in to the platform.', 403, 'renter_signup_disabled');
|
||||
}
|
||||
function loginDisabled() {
|
||||
throw new errors_1.AppError('Renter sign-in is disabled. Only company owners can sign in to the platform.', 403, 'renter_login_disabled');
|
||||
}
|
||||
async function getMe(renterId) {
|
||||
const renter = await repo.findRenterProfile(renterId);
|
||||
const savedCompanies = await repo.findSavedCompanies(renter.savedCompanies.map((savedCompany) => savedCompany.companyId));
|
||||
return (0, auth_presenter_1.presentRenterProfile)(renter, savedCompanies);
|
||||
}
|
||||
function updateMe(renterId, body) {
|
||||
return repo.updateRenterProfile(renterId, body);
|
||||
}
|
||||
async function updateFcmToken(renterId, fcmToken) {
|
||||
await repo.updateRenterFcmToken(renterId, fcmToken);
|
||||
return { success: true };
|
||||
}
|
||||
//# sourceMappingURL=auth.renter.service.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.renter.service.js","sourceRoot":"","sources":["../../../src/modules/auth/auth.renter.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,wCAEC;AAED,sCAEC;AAED,sBAIC;AAED,4BAEC;AAED,wCAGC;AA7BD,8CAA4C;AAC5C,qDAAuD;AACvD,yDAA0C;AAM1C,SAAgB,cAAc;IAC5B,MAAM,IAAI,iBAAQ,CAAC,uFAAuF,EAAE,GAAG,EAAE,wBAAwB,CAAC,CAAA;AAC5I,CAAC;AAED,SAAgB,aAAa;IAC3B,MAAM,IAAI,iBAAQ,CAAC,8EAA8E,EAAE,GAAG,EAAE,uBAAuB,CAAC,CAAA;AAClI,CAAC;AAEM,KAAK,UAAU,KAAK,CAAC,QAAgB;IAC1C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAA;IACrD,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,YAAiB,EAAE,EAAE,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAA;IAC9H,OAAO,IAAA,qCAAoB,EAAC,MAAM,EAAE,cAAc,CAAC,CAAA;AACrD,CAAC;AAED,SAAgB,QAAQ,CAAC,QAAgB,EAAE,IAAuB;IAChE,OAAO,IAAI,CAAC,mBAAmB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;AACjD,CAAC;AAEM,KAAK,UAAU,cAAc,CAAC,QAAgB,EAAE,QAAgB;IACrE,MAAM,IAAI,CAAC,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;IACnD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;AAC1B,CAAC"}
|
||||
Reference in New Issue
Block a user