@asumano/worklip-typeorm-db 1.1.95 → 1.1.96
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.link.rules.d.ts +42 -0
- package/dist/client.link.rules.js +95 -0
- package/dist/client.plan.rules.d.ts +72 -0
- package/dist/client.plan.rules.js +137 -0
- package/dist/entities/Appointment.js +1 -1
- package/dist/entities/Client.d.ts +18 -3
- package/dist/entities/Client.js +77 -14
- package/dist/entities/ClientIdentity.d.ts +10 -0
- package/dist/entities/ClientIdentity.js +83 -0
- package/dist/entities/ClientPlan.d.ts +19 -0
- package/dist/entities/ClientPlan.js +150 -0
- package/dist/entities/ClientPlanLimit.d.ts +7 -0
- package/dist/entities/ClientPlanLimit.js +57 -0
- package/dist/entities/ClientSession.d.ts +14 -0
- package/dist/entities/ClientSession.js +121 -0
- package/dist/entities/ClientSubscription.d.ts +19 -0
- package/dist/entities/ClientSubscription.js +139 -0
- package/dist/entities/ClientVehicle.d.ts +18 -0
- package/dist/entities/ClientVehicle.js +148 -0
- package/dist/entities/CompanyClient.d.ts +15 -0
- package/dist/entities/CompanyClient.js +115 -0
- package/dist/entities/CompanyVehicle.d.ts +14 -0
- package/dist/entities/CompanyVehicle.js +104 -0
- package/dist/entities/Reminder.d.ts +2 -1
- package/dist/entities/Reminder.js +12 -2
- package/dist/entities/Vehicle.d.ts +10 -1
- package/dist/entities/Vehicle.js +59 -5
- package/dist/entities.index.d.ts +8 -0
- package/dist/entities.index.js +22 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +6 -0
- package/dist/views/Clients.d.ts +13 -2
- package/dist/views/Clients.js +49 -2
- package/dist/views/Vehicles.d.ts +10 -0
- package/dist/views/Vehicles.js +41 -0
- package/package.json +1 -1
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export declare const CLIENT_IDENTITY_TYPE: {
|
|
2
|
+
readonly GOOGLE: 1;
|
|
3
|
+
readonly EMAIL: 2;
|
|
4
|
+
readonly WHATSAPP: 3;
|
|
5
|
+
};
|
|
6
|
+
export type TClientIdentityType = (typeof CLIENT_IDENTITY_TYPE)[keyof typeof CLIENT_IDENTITY_TYPE];
|
|
7
|
+
/**
|
|
8
|
+
* DOC: Deja el valor de la identidad en su forma única. Sin esto el UNIQUE (type, value) no
|
|
9
|
+
* sirve: `Juan@Gmail.com` y `juan@gmail.com` serían dos cuentas del mismo correo.
|
|
10
|
+
* El celular va solo con dígitos y con indicativo (573123123232), como lo entrega Meta.
|
|
11
|
+
*/
|
|
12
|
+
export declare const normalizeClientIdentity: (type: number, value: string) => string;
|
|
13
|
+
export declare const COMPANY_LINK_STATUS: {
|
|
14
|
+
readonly INACTIVE: 0;
|
|
15
|
+
readonly ACTIVE: 1;
|
|
16
|
+
readonly UNLINKED: 2;
|
|
17
|
+
};
|
|
18
|
+
export declare const COMPANY_LINK_SOURCE: {
|
|
19
|
+
readonly REGISTERED: 1;
|
|
20
|
+
readonly LINKED: 2;
|
|
21
|
+
readonly CLIENT_BOOKED: 3;
|
|
22
|
+
};
|
|
23
|
+
export declare const CLIENT_VEHICLE_ROLE: {
|
|
24
|
+
readonly OWNER: 1;
|
|
25
|
+
readonly SHARED: 2;
|
|
26
|
+
};
|
|
27
|
+
export declare const CLIENT_VEHICLE_STATUS: {
|
|
28
|
+
readonly ENDED: 0;
|
|
29
|
+
readonly ACTIVE: 1;
|
|
30
|
+
readonly PENDING: 2;
|
|
31
|
+
};
|
|
32
|
+
interface ICompanyContactAccess {
|
|
33
|
+
originCompany: number | null;
|
|
34
|
+
company: number;
|
|
35
|
+
linkStatus: number;
|
|
36
|
+
hasAccount: boolean;
|
|
37
|
+
}
|
|
38
|
+
export declare const canCompanySeeFullContact: ({ originCompany, company, linkStatus, }: ICompanyContactAccess) => boolean;
|
|
39
|
+
export declare const canCompanyEditContact: (access: ICompanyContactAccess) => boolean;
|
|
40
|
+
export declare const maskEmail: (email: string | null | undefined) => string | null;
|
|
41
|
+
export declare const maskPhone: (phone: string | null | undefined) => string | null;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// DOC: Reglas del cliente GLOBAL: el cliente es de Worklip y las empresas se VINCULAN a él.
|
|
3
|
+
// Viven acá porque el API las hace cumplir, el portal pinta el contacto enmascarado y la app
|
|
4
|
+
// del cliente muestra sus vínculos; tres copias de «quién ve qué» se desvían.
|
|
5
|
+
//
|
|
6
|
+
// Módulo PURO: sin TypeORM, para que los fronts lo importen por ruta profunda.
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.maskPhone = exports.maskEmail = exports.canCompanyEditContact = exports.canCompanySeeFullContact = exports.CLIENT_VEHICLE_STATUS = exports.CLIENT_VEHICLE_ROLE = exports.COMPANY_LINK_SOURCE = exports.COMPANY_LINK_STATUS = exports.normalizeClientIdentity = exports.CLIENT_IDENTITY_TYPE = void 0;
|
|
9
|
+
// DOC: Con qué se entra a la app. Solo se guardan identidades YA verificadas.
|
|
10
|
+
exports.CLIENT_IDENTITY_TYPE = {
|
|
11
|
+
GOOGLE: 1,
|
|
12
|
+
EMAIL: 2,
|
|
13
|
+
WHATSAPP: 3,
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* DOC: Deja el valor de la identidad en su forma única. Sin esto el UNIQUE (type, value) no
|
|
17
|
+
* sirve: `Juan@Gmail.com` y `juan@gmail.com` serían dos cuentas del mismo correo.
|
|
18
|
+
* El celular va solo con dígitos y con indicativo (573123123232), como lo entrega Meta.
|
|
19
|
+
*/
|
|
20
|
+
const normalizeClientIdentity = (type, value) => {
|
|
21
|
+
const trimmed = String(value ?? "").trim();
|
|
22
|
+
if (type === exports.CLIENT_IDENTITY_TYPE.EMAIL)
|
|
23
|
+
return trimmed.toLowerCase();
|
|
24
|
+
if (type === exports.CLIENT_IDENTITY_TYPE.WHATSAPP)
|
|
25
|
+
return trimmed.replace(/\D/g, "");
|
|
26
|
+
return trimmed;
|
|
27
|
+
};
|
|
28
|
+
exports.normalizeClientIdentity = normalizeClientIdentity;
|
|
29
|
+
// DOC: Estado del vínculo empresa-cliente (`company_client.status`) y empresa-vehículo.
|
|
30
|
+
exports.COMPANY_LINK_STATUS = {
|
|
31
|
+
// DOC: El taller lo desactivó. Solo para ESA empresa: en las demás sigue igual.
|
|
32
|
+
INACTIVE: 0,
|
|
33
|
+
ACTIVE: 1,
|
|
34
|
+
// DOC: El CLIENTE se desvinculó desde la app. El taller conserva sus visitas pero pierde el
|
|
35
|
+
// contacto y los envíos, y volver a vincularlo pide la confirmación del cliente.
|
|
36
|
+
UNLINKED: 2,
|
|
37
|
+
};
|
|
38
|
+
// DOC: Cómo nació el vínculo.
|
|
39
|
+
exports.COMPANY_LINK_SOURCE = {
|
|
40
|
+
// DOC: La empresa lo registró: es el ORIGEN (`client.company`) y ve el contacto completo.
|
|
41
|
+
REGISTERED: 1,
|
|
42
|
+
// DOC: Ya existía en Worklip y el taller lo vinculó al buscarlo por documento o placa.
|
|
43
|
+
LINKED: 2,
|
|
44
|
+
// DOC: El cliente agendó una cita desde la app.
|
|
45
|
+
CLIENT_BOOKED: 3,
|
|
46
|
+
};
|
|
47
|
+
// DOC: Relación cliente-vehículo (`client_vehicle`).
|
|
48
|
+
exports.CLIENT_VEHICLE_ROLE = {
|
|
49
|
+
OWNER: 1,
|
|
50
|
+
// DOC: Un familiar al que el dueño le compartió el vehículo (premium).
|
|
51
|
+
SHARED: 2,
|
|
52
|
+
};
|
|
53
|
+
exports.CLIENT_VEHICLE_STATUS = {
|
|
54
|
+
// DOC: Terminó: se vendió o el dueño dejó de compartirlo. Se conserva por historia.
|
|
55
|
+
ENDED: 0,
|
|
56
|
+
ACTIVE: 1,
|
|
57
|
+
// DOC: Esperando al dueño: una invitación a un familiar, o un taller que registró una placa
|
|
58
|
+
// que ya tiene dueño. No da acceso a nada hasta que se acepte.
|
|
59
|
+
PENDING: 2,
|
|
60
|
+
};
|
|
61
|
+
// DOC: Solo el taller que lo REGISTRÓ ve el correo y el celular completos. Los demás
|
|
62
|
+
// trabajan con el enmascarado: los envíos los hace Worklip con el dato completo.
|
|
63
|
+
const canCompanySeeFullContact = ({ originCompany, company, linkStatus, }) => linkStatus === exports.COMPANY_LINK_STATUS.ACTIVE &&
|
|
64
|
+
originCompany !== null &&
|
|
65
|
+
originCompany === company;
|
|
66
|
+
exports.canCompanySeeFullContact = canCompanySeeFullContact;
|
|
67
|
+
// DOC: Con cuenta, el contacto es del cliente: es con lo que entra a la app, y dejar que el
|
|
68
|
+
// taller lo cambie sería dejarlo quitarle la cuenta.
|
|
69
|
+
const canCompanyEditContact = (access) => !access.hasAccount && (0, exports.canCompanySeeFullContact)(access);
|
|
70
|
+
exports.canCompanyEditContact = canCompanyEditContact;
|
|
71
|
+
// DOC: `jgomezp97@gmail.com` -> `j*******7@gmail.com`. Deja la primera y la última letra
|
|
72
|
+
// para que el asesor confirme con el cliente sin leerle el dato.
|
|
73
|
+
const maskEmail = (email) => {
|
|
74
|
+
if (!email)
|
|
75
|
+
return null;
|
|
76
|
+
const at = email.lastIndexOf("@");
|
|
77
|
+
if (at <= 0)
|
|
78
|
+
return "****";
|
|
79
|
+
const user = email.slice(0, at);
|
|
80
|
+
const domain = email.slice(at);
|
|
81
|
+
if (user.length <= 2)
|
|
82
|
+
return `${user[0]}*${domain}`;
|
|
83
|
+
return `${user[0]}${"*".repeat(user.length - 2)}${user[user.length - 1]}${domain}`;
|
|
84
|
+
};
|
|
85
|
+
exports.maskEmail = maskEmail;
|
|
86
|
+
// DOC: `3123123232` -> `*** *** 3232`. Solo los últimos cuatro dígitos.
|
|
87
|
+
const maskPhone = (phone) => {
|
|
88
|
+
if (!phone)
|
|
89
|
+
return null;
|
|
90
|
+
const digits = String(phone).replace(/\D/g, "");
|
|
91
|
+
if (digits.length <= 4)
|
|
92
|
+
return "****";
|
|
93
|
+
return `*** *** ${digits.slice(-4)}`;
|
|
94
|
+
};
|
|
95
|
+
exports.maskPhone = maskPhone;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DOC: LOS CÓDIGOS DE LÍMITE. La única fuente: un código que no esté acá no lo pregunta nadie.
|
|
3
|
+
*
|
|
4
|
+
* En `client_plan_limit.value`: un número es el tope, NULL es ilimitado y la FILA AUSENTE es
|
|
5
|
+
* 0. Falla cerrado: un plan mal configurado no regala premium.
|
|
6
|
+
*/
|
|
7
|
+
export declare const CLIENT_PLAN_LIMIT: {
|
|
8
|
+
readonly MAX_VEHICLES: "MAX_VEHICLES";
|
|
9
|
+
readonly MAX_OWN_REMINDERS: "MAX_OWN_REMINDERS";
|
|
10
|
+
readonly WHATSAPP_REMINDERS: "WHATSAPP_REMINDERS";
|
|
11
|
+
readonly MAX_DOCUMENTS: "MAX_DOCUMENTS";
|
|
12
|
+
readonly MAX_SHARED_MEMBERS: "MAX_SHARED_MEMBERS";
|
|
13
|
+
};
|
|
14
|
+
export type TClientPlanLimit = (typeof CLIENT_PLAN_LIMIT)[keyof typeof CLIENT_PLAN_LIMIT];
|
|
15
|
+
export declare const CLIENT_PLAN_LIMITS: TClientPlanLimit[];
|
|
16
|
+
export declare const CLIENT_PLAN_FLAGS: TClientPlanLimit[];
|
|
17
|
+
export declare const isClientPlanLimit: (code: string) => code is TClientPlanLimit;
|
|
18
|
+
export declare const CLIENT_PLAN_PERIOD: {
|
|
19
|
+
readonly MONTHLY: 1;
|
|
20
|
+
readonly YEARLY: 2;
|
|
21
|
+
};
|
|
22
|
+
export declare const CLIENT_SUBSCRIPTION_STATUS: {
|
|
23
|
+
readonly ACTIVE: 1;
|
|
24
|
+
readonly CANCELED: 2;
|
|
25
|
+
readonly EXPIRED: 3;
|
|
26
|
+
readonly REVOKED: 4;
|
|
27
|
+
};
|
|
28
|
+
export declare const CLIENT_SUBSCRIPTION_PROVIDER: {
|
|
29
|
+
readonly APPLE: "apple";
|
|
30
|
+
readonly GOOGLE: "google";
|
|
31
|
+
readonly MANUAL: "manual";
|
|
32
|
+
};
|
|
33
|
+
export interface IClientSubscriptionLike {
|
|
34
|
+
plan: number;
|
|
35
|
+
status: number;
|
|
36
|
+
period_start: Date | string;
|
|
37
|
+
period_end: Date | string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* DOC: La suscripción que vale AHORA, o null (= plan gratuito, como Spotify).
|
|
41
|
+
*
|
|
42
|
+
* Si tiene dos (una de la tienda y un regalo manual), vale la que vence más tarde.
|
|
43
|
+
*/
|
|
44
|
+
export declare const resolveActiveClientSubscription: <T extends IClientSubscriptionLike>(subscriptions: T[], now?: Date) => T | null;
|
|
45
|
+
export type TClientPlanLimits = Partial<Record<string, number | null>>;
|
|
46
|
+
export declare const getClientPlanLimit: (limits: TClientPlanLimits, code: TClientPlanLimit) => number | null;
|
|
47
|
+
export declare const canAddUnderClientLimit: (limits: TClientPlanLimits, code: TClientPlanLimit, currentCount: number) => boolean;
|
|
48
|
+
export declare const isClientPlanFlagOn: (limits: TClientPlanLimits, code: TClientPlanLimit) => boolean;
|
|
49
|
+
export declare const REMINDER_NOTIFY_PINNED_KEY = "notify_pinned";
|
|
50
|
+
export interface IClientReminderLike {
|
|
51
|
+
id: number;
|
|
52
|
+
reminder_date: string;
|
|
53
|
+
details?: any;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* DOC: Cuáles recordatorios PROPIOS del cliente avisan. Los escogidos primero y después los
|
|
57
|
+
* que vencen más pronto, hasta el tope; el resto sale con «Sin aviso: su plan actual no lo
|
|
58
|
+
* incluye». Se le pasan solo los pendientes y solo los que creó el cliente.
|
|
59
|
+
*/
|
|
60
|
+
export declare const pickNotifiableClientReminders: <T extends IClientReminderLike>(reminders: T[], limit: number | null) => Set<number>;
|
|
61
|
+
export declare const REMINDER_SEND_VIA: {
|
|
62
|
+
readonly EMAIL: 1;
|
|
63
|
+
readonly WHATSAPP: 2;
|
|
64
|
+
readonly BOTH: 3;
|
|
65
|
+
readonly APP: 4;
|
|
66
|
+
};
|
|
67
|
+
export type TReminderChannel = "email" | "whatsapp" | "app";
|
|
68
|
+
/**
|
|
69
|
+
* DOC: Por dónde sale un recordatorio del CLIENTE. La notificación de la app va siempre; sin
|
|
70
|
+
* WhatsApp en el plan, ese canal se cae pero el recordatorio NUNCA queda mudo.
|
|
71
|
+
*/
|
|
72
|
+
export declare const clientReminderChannels: (sendVia: number, whatsappAllowed: boolean) => TReminderChannel[];
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// DOC: Planes del CLIENTE (gratuito y premium). Van aparte de los de la empresa: aquellos
|
|
3
|
+
// cuentan talleres, usuarios y mensajes, y mezclarlos llenaría todo de «si es cliente...».
|
|
4
|
+
// Lo resuelven el API (para frenar), la app (para pintar el candado) y el panel (para
|
|
5
|
+
// editar los límites), así que la cuenta es una sola.
|
|
6
|
+
//
|
|
7
|
+
// Módulo PURO: sin TypeORM, para que los fronts lo importen por ruta profunda.
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.clientReminderChannels = exports.REMINDER_SEND_VIA = exports.pickNotifiableClientReminders = exports.REMINDER_NOTIFY_PINNED_KEY = exports.isClientPlanFlagOn = exports.canAddUnderClientLimit = exports.getClientPlanLimit = exports.resolveActiveClientSubscription = exports.CLIENT_SUBSCRIPTION_PROVIDER = exports.CLIENT_SUBSCRIPTION_STATUS = exports.CLIENT_PLAN_PERIOD = exports.isClientPlanLimit = exports.CLIENT_PLAN_FLAGS = exports.CLIENT_PLAN_LIMITS = exports.CLIENT_PLAN_LIMIT = void 0;
|
|
10
|
+
/**
|
|
11
|
+
* DOC: LOS CÓDIGOS DE LÍMITE. La única fuente: un código que no esté acá no lo pregunta nadie.
|
|
12
|
+
*
|
|
13
|
+
* En `client_plan_limit.value`: un número es el tope, NULL es ilimitado y la FILA AUSENTE es
|
|
14
|
+
* 0. Falla cerrado: un plan mal configurado no regala premium.
|
|
15
|
+
*/
|
|
16
|
+
exports.CLIENT_PLAN_LIMIT = {
|
|
17
|
+
// DOC: Vehículos propios. Los compartidos por un familiar no cuentan.
|
|
18
|
+
MAX_VEHICLES: "MAX_VEHICLES",
|
|
19
|
+
// DOC: Recordatorios que crea el cliente y que AVISAN. Los del taller no cuentan: esos los
|
|
20
|
+
// paga el taller con su plan.
|
|
21
|
+
MAX_OWN_REMINDERS: "MAX_OWN_REMINDERS",
|
|
22
|
+
// DOC: 1 = sus recordatorios pueden salir por WhatsApp; 0 = pasan a la notificación de la app.
|
|
23
|
+
WHATSAPP_REMINDERS: "WHATSAPP_REMINDERS",
|
|
24
|
+
// DOC: Documentos guardados (SOAT, tarjeta de propiedad). Ver y descargar nunca se bloquea.
|
|
25
|
+
MAX_DOCUMENTS: "MAX_DOCUMENTS",
|
|
26
|
+
// DOC: Personas con las que puede compartir sus vehículos. 0 = no comparte.
|
|
27
|
+
MAX_SHARED_MEMBERS: "MAX_SHARED_MEMBERS",
|
|
28
|
+
};
|
|
29
|
+
exports.CLIENT_PLAN_LIMITS = Object.values(exports.CLIENT_PLAN_LIMIT);
|
|
30
|
+
// DOC: Los que son sí/no y no una cantidad; el panel los pinta como interruptor.
|
|
31
|
+
exports.CLIENT_PLAN_FLAGS = [
|
|
32
|
+
exports.CLIENT_PLAN_LIMIT.WHATSAPP_REMINDERS,
|
|
33
|
+
];
|
|
34
|
+
const isClientPlanLimit = (code) => exports.CLIENT_PLAN_LIMITS.includes(code);
|
|
35
|
+
exports.isClientPlanLimit = isClientPlanLimit;
|
|
36
|
+
exports.CLIENT_PLAN_PERIOD = {
|
|
37
|
+
MONTHLY: 1,
|
|
38
|
+
YEARLY: 2,
|
|
39
|
+
};
|
|
40
|
+
exports.CLIENT_SUBSCRIPTION_STATUS = {
|
|
41
|
+
// DOC: Pagada y se renueva sola.
|
|
42
|
+
ACTIVE: 1,
|
|
43
|
+
// DOC: Canceló la renovación: vale hasta `period_end` y después pasa al gratuito.
|
|
44
|
+
CANCELED: 2,
|
|
45
|
+
EXPIRED: 3,
|
|
46
|
+
// DOC: Reembolsada o revocada por la tienda: se corta YA, sin esperar el fin del periodo.
|
|
47
|
+
REVOKED: 4,
|
|
48
|
+
};
|
|
49
|
+
// DOC: Quién cobra. En la tienda manda la tienda: el panel solo MIRA esas filas. La `manual` es
|
|
50
|
+
// el premium que regala Worklip y es la única que se edita.
|
|
51
|
+
exports.CLIENT_SUBSCRIPTION_PROVIDER = {
|
|
52
|
+
APPLE: "apple",
|
|
53
|
+
GOOGLE: "google",
|
|
54
|
+
MANUAL: "manual",
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* DOC: La suscripción que vale AHORA, o null (= plan gratuito, como Spotify).
|
|
58
|
+
*
|
|
59
|
+
* Si tiene dos (una de la tienda y un regalo manual), vale la que vence más tarde.
|
|
60
|
+
*/
|
|
61
|
+
const resolveActiveClientSubscription = (subscriptions, now = new Date()) => {
|
|
62
|
+
const at = now.getTime();
|
|
63
|
+
let best = null;
|
|
64
|
+
for (const sub of subscriptions) {
|
|
65
|
+
const valid = sub.status === exports.CLIENT_SUBSCRIPTION_STATUS.ACTIVE ||
|
|
66
|
+
sub.status === exports.CLIENT_SUBSCRIPTION_STATUS.CANCELED;
|
|
67
|
+
if (!valid)
|
|
68
|
+
continue;
|
|
69
|
+
const start = new Date(sub.period_start).getTime();
|
|
70
|
+
const end = new Date(sub.period_end).getTime();
|
|
71
|
+
if (!(start <= at && at < end))
|
|
72
|
+
continue;
|
|
73
|
+
if (!best || end > new Date(best.period_end).getTime())
|
|
74
|
+
best = sub;
|
|
75
|
+
}
|
|
76
|
+
return best;
|
|
77
|
+
};
|
|
78
|
+
exports.resolveActiveClientSubscription = resolveActiveClientSubscription;
|
|
79
|
+
// DOC: El tope de un código: número, o null si es ilimitado. Ausente = 0 (falla cerrado).
|
|
80
|
+
const getClientPlanLimit = (limits, code) => {
|
|
81
|
+
if (!(code in limits))
|
|
82
|
+
return 0;
|
|
83
|
+
const value = limits[code];
|
|
84
|
+
return value === null || value === undefined ? null : Math.max(0, value);
|
|
85
|
+
};
|
|
86
|
+
exports.getClientPlanLimit = getClientPlanLimit;
|
|
87
|
+
// DOC: ¿Puede agregar UNO más? Lo que ya tiene por encima del tope no se borra ni se
|
|
88
|
+
// esconde: queda congelado, pero no suma.
|
|
89
|
+
const canAddUnderClientLimit = (limits, code, currentCount) => {
|
|
90
|
+
const limit = (0, exports.getClientPlanLimit)(limits, code);
|
|
91
|
+
return limit === null || currentCount < limit;
|
|
92
|
+
};
|
|
93
|
+
exports.canAddUnderClientLimit = canAddUnderClientLimit;
|
|
94
|
+
const isClientPlanFlagOn = (limits, code) => {
|
|
95
|
+
const limit = (0, exports.getClientPlanLimit)(limits, code);
|
|
96
|
+
return limit === null || limit > 0;
|
|
97
|
+
};
|
|
98
|
+
exports.isClientPlanFlagOn = isClientPlanFlagOn;
|
|
99
|
+
// DOC: Llave en `reminder.details` con la que el cliente escoge cuáles siguen avisando cuando
|
|
100
|
+
// tiene más de los que su plan permite.
|
|
101
|
+
exports.REMINDER_NOTIFY_PINNED_KEY = "notify_pinned";
|
|
102
|
+
/**
|
|
103
|
+
* DOC: Cuáles recordatorios PROPIOS del cliente avisan. Los escogidos primero y después los
|
|
104
|
+
* que vencen más pronto, hasta el tope; el resto sale con «Sin aviso: su plan actual no lo
|
|
105
|
+
* incluye». Se le pasan solo los pendientes y solo los que creó el cliente.
|
|
106
|
+
*/
|
|
107
|
+
const pickNotifiableClientReminders = (reminders, limit) => {
|
|
108
|
+
if (limit === null)
|
|
109
|
+
return new Set(reminders.map((r) => r.id));
|
|
110
|
+
const pinned = (r) => (r.details?.[exports.REMINDER_NOTIFY_PINNED_KEY] ? 0 : 1);
|
|
111
|
+
const ordered = [...reminders].sort((a, b) => pinned(a) - pinned(b) ||
|
|
112
|
+
a.reminder_date.localeCompare(b.reminder_date) ||
|
|
113
|
+
a.id - b.id);
|
|
114
|
+
return new Set(ordered.slice(0, Math.max(0, limit)).map((r) => r.id));
|
|
115
|
+
};
|
|
116
|
+
exports.pickNotifiableClientReminders = pickNotifiableClientReminders;
|
|
117
|
+
// DOC: `reminder.send_via`. El 4 es nuevo y es el canal que no cuesta.
|
|
118
|
+
exports.REMINDER_SEND_VIA = {
|
|
119
|
+
EMAIL: 1,
|
|
120
|
+
WHATSAPP: 2,
|
|
121
|
+
BOTH: 3,
|
|
122
|
+
APP: 4,
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* DOC: Por dónde sale un recordatorio del CLIENTE. La notificación de la app va siempre; sin
|
|
126
|
+
* WhatsApp en el plan, ese canal se cae pero el recordatorio NUNCA queda mudo.
|
|
127
|
+
*/
|
|
128
|
+
const clientReminderChannels = (sendVia, whatsappAllowed) => {
|
|
129
|
+
const channels = ["app"];
|
|
130
|
+
if (sendVia === exports.REMINDER_SEND_VIA.EMAIL || sendVia === exports.REMINDER_SEND_VIA.BOTH)
|
|
131
|
+
channels.push("email");
|
|
132
|
+
if (whatsappAllowed &&
|
|
133
|
+
(sendVia === exports.REMINDER_SEND_VIA.WHATSAPP || sendVia === exports.REMINDER_SEND_VIA.BOTH))
|
|
134
|
+
channels.push("whatsapp");
|
|
135
|
+
return channels;
|
|
136
|
+
};
|
|
137
|
+
exports.clientReminderChannels = clientReminderChannels;
|
|
@@ -132,7 +132,7 @@ __decorate([
|
|
|
132
132
|
default: 3,
|
|
133
133
|
type: "int",
|
|
134
134
|
width: 1,
|
|
135
|
-
comment: "Por dónde entró la cita:\n1. Chatbot de WhatsApp.\n2. Enlace público del cliente.\n3. El taller la creó.\n4. Botón del correo del recordatorio.",
|
|
135
|
+
comment: "Por dónde entró la cita:\n1. Chatbot de WhatsApp.\n2. Enlace público del cliente.\n3. El taller la creó.\n4. Botón del correo del recordatorio.\n5. App del cliente.",
|
|
136
136
|
}),
|
|
137
137
|
__metadata("design:type", Number)
|
|
138
138
|
], Appointment.prototype, "source", void 0);
|
|
@@ -2,17 +2,32 @@ import { City } from "./City";
|
|
|
2
2
|
import { Company } from "./Company";
|
|
3
3
|
import { ServiceOrder } from "./ServiceOrder";
|
|
4
4
|
import { Reminder } from "./Reminder";
|
|
5
|
+
import { Associate } from "./Associate";
|
|
6
|
+
import { CompanyClient } from "./CompanyClient";
|
|
7
|
+
import { ClientVehicle } from "./ClientVehicle";
|
|
8
|
+
import { ClientIdentity } from "./ClientIdentity";
|
|
9
|
+
import { ClientSession } from "./ClientSession";
|
|
10
|
+
import { ClientSubscription } from "./ClientSubscription";
|
|
5
11
|
export declare class Client {
|
|
6
12
|
id: number;
|
|
7
13
|
document: string;
|
|
8
|
-
|
|
14
|
+
document_type: string;
|
|
15
|
+
company: Company | null;
|
|
16
|
+
created_by: Associate | null;
|
|
9
17
|
name: string;
|
|
10
18
|
surname: string;
|
|
11
|
-
email: string;
|
|
12
|
-
phone: string;
|
|
19
|
+
email: string | null;
|
|
20
|
+
phone: string | null;
|
|
13
21
|
city: City;
|
|
14
22
|
details: any | null;
|
|
15
23
|
status: number;
|
|
24
|
+
created: Date;
|
|
25
|
+
updated: Date | null;
|
|
16
26
|
service_orders: ServiceOrder[];
|
|
17
27
|
reminders: Reminder[];
|
|
28
|
+
company_links: CompanyClient[];
|
|
29
|
+
vehicle_links: ClientVehicle[];
|
|
30
|
+
identities: ClientIdentity[];
|
|
31
|
+
sessions: ClientSession[];
|
|
32
|
+
subscriptions: ClientSubscription[];
|
|
18
33
|
}
|
package/dist/entities/Client.js
CHANGED
|
@@ -15,6 +15,14 @@ const City_1 = require("./City");
|
|
|
15
15
|
const Company_1 = require("./Company");
|
|
16
16
|
const ServiceOrder_1 = require("./ServiceOrder");
|
|
17
17
|
const Reminder_1 = require("./Reminder");
|
|
18
|
+
const Associate_1 = require("./Associate");
|
|
19
|
+
const CompanyClient_1 = require("./CompanyClient");
|
|
20
|
+
const ClientVehicle_1 = require("./ClientVehicle");
|
|
21
|
+
const ClientIdentity_1 = require("./ClientIdentity");
|
|
22
|
+
const ClientSession_1 = require("./ClientSession");
|
|
23
|
+
const ClientSubscription_1 = require("./ClientSubscription");
|
|
24
|
+
// DOC: El cliente es de WORKLIP, no de una empresa: las empresas se vinculan a él en
|
|
25
|
+
// `company_client`. Lo identifica el documento en toda la plataforma.
|
|
18
26
|
let Client = class Client {
|
|
19
27
|
};
|
|
20
28
|
exports.Client = Client;
|
|
@@ -33,14 +41,32 @@ __decorate([
|
|
|
33
41
|
}),
|
|
34
42
|
__metadata("design:type", String)
|
|
35
43
|
], Client.prototype, "document", void 0);
|
|
44
|
+
__decorate([
|
|
45
|
+
(0, typeorm_1.Column)({
|
|
46
|
+
type: "varchar",
|
|
47
|
+
length: 10,
|
|
48
|
+
comment: "Tipo de documento del cliente (C.C, NIT, ...).",
|
|
49
|
+
}),
|
|
50
|
+
__metadata("design:type", String)
|
|
51
|
+
], Client.prototype, "document_type", void 0);
|
|
36
52
|
__decorate([
|
|
37
53
|
(0, typeorm_1.ManyToOne)(() => Company_1.Company, (company) => company.clients, {
|
|
38
|
-
onDelete: "
|
|
54
|
+
onDelete: "SET NULL",
|
|
39
55
|
onUpdate: "NO ACTION",
|
|
56
|
+
nullable: true,
|
|
40
57
|
}),
|
|
41
58
|
(0, typeorm_1.JoinColumn)({ name: "company" }),
|
|
42
|
-
__metadata("design:type",
|
|
59
|
+
__metadata("design:type", Object)
|
|
43
60
|
], Client.prototype, "company", void 0);
|
|
61
|
+
__decorate([
|
|
62
|
+
(0, typeorm_1.ManyToOne)(() => Associate_1.Associate, {
|
|
63
|
+
onDelete: "SET NULL",
|
|
64
|
+
onUpdate: "NO ACTION",
|
|
65
|
+
nullable: true,
|
|
66
|
+
}),
|
|
67
|
+
(0, typeorm_1.JoinColumn)({ name: "created_by" }),
|
|
68
|
+
__metadata("design:type", Object)
|
|
69
|
+
], Client.prototype, "created_by", void 0);
|
|
44
70
|
__decorate([
|
|
45
71
|
(0, typeorm_1.Column)({ length: 50, type: "varchar", comment: "Nombre del cliente." }),
|
|
46
72
|
__metadata("design:type", String)
|
|
@@ -57,17 +83,21 @@ __decorate([
|
|
|
57
83
|
(0, typeorm_1.Column)({
|
|
58
84
|
type: "varchar",
|
|
59
85
|
length: 100,
|
|
60
|
-
|
|
86
|
+
nullable: true,
|
|
87
|
+
default: null,
|
|
88
|
+
comment: "Correo electrónico de contacto del cliente.",
|
|
61
89
|
}),
|
|
62
|
-
__metadata("design:type",
|
|
90
|
+
__metadata("design:type", Object)
|
|
63
91
|
], Client.prototype, "email", void 0);
|
|
64
92
|
__decorate([
|
|
65
93
|
(0, typeorm_1.Column)({
|
|
66
94
|
type: "varchar",
|
|
67
95
|
length: 12,
|
|
68
|
-
|
|
96
|
+
nullable: true,
|
|
97
|
+
default: null,
|
|
98
|
+
comment: "Número de celular de contacto del cliente.",
|
|
69
99
|
}),
|
|
70
|
-
__metadata("design:type",
|
|
100
|
+
__metadata("design:type", Object)
|
|
71
101
|
], Client.prototype, "phone", void 0);
|
|
72
102
|
__decorate([
|
|
73
103
|
(0, typeorm_1.ManyToOne)(() => City_1.City, (city) => city.clients, {
|
|
@@ -91,10 +121,28 @@ __decorate([
|
|
|
91
121
|
default: 1,
|
|
92
122
|
type: "int",
|
|
93
123
|
width: 1,
|
|
94
|
-
comment: "Estado
|
|
124
|
+
comment: "Estado de la cuenta en TODA la plataforma (el de cada empresa va en company_client.status).\r\n1: Activo.\r\n0: Suspendido por Worklip.",
|
|
95
125
|
}),
|
|
96
126
|
__metadata("design:type", Number)
|
|
97
127
|
], Client.prototype, "status", void 0);
|
|
128
|
+
__decorate([
|
|
129
|
+
(0, typeorm_1.Column)({
|
|
130
|
+
type: "datetime",
|
|
131
|
+
comment: "Fecha de creación del registro.",
|
|
132
|
+
default: () => "CURRENT_TIMESTAMP",
|
|
133
|
+
}),
|
|
134
|
+
__metadata("design:type", Date)
|
|
135
|
+
], Client.prototype, "created", void 0);
|
|
136
|
+
__decorate([
|
|
137
|
+
(0, typeorm_1.Column)({
|
|
138
|
+
type: "datetime",
|
|
139
|
+
nullable: true,
|
|
140
|
+
default: null,
|
|
141
|
+
comment: "Fecha de actualización del registro.",
|
|
142
|
+
onUpdate: "CURRENT_TIMESTAMP",
|
|
143
|
+
}),
|
|
144
|
+
__metadata("design:type", Object)
|
|
145
|
+
], Client.prototype, "updated", void 0);
|
|
98
146
|
__decorate([
|
|
99
147
|
(0, typeorm_1.OneToMany)(() => ServiceOrder_1.ServiceOrder, (serviceOrder) => serviceOrder.client),
|
|
100
148
|
__metadata("design:type", Array)
|
|
@@ -103,14 +151,29 @@ __decorate([
|
|
|
103
151
|
(0, typeorm_1.OneToMany)(() => Reminder_1.Reminder, (reminder) => reminder.client),
|
|
104
152
|
__metadata("design:type", Array)
|
|
105
153
|
], Client.prototype, "reminders", void 0);
|
|
154
|
+
__decorate([
|
|
155
|
+
(0, typeorm_1.OneToMany)(() => CompanyClient_1.CompanyClient, (link) => link.client),
|
|
156
|
+
__metadata("design:type", Array)
|
|
157
|
+
], Client.prototype, "company_links", void 0);
|
|
158
|
+
__decorate([
|
|
159
|
+
(0, typeorm_1.OneToMany)(() => ClientVehicle_1.ClientVehicle, (link) => link.client),
|
|
160
|
+
__metadata("design:type", Array)
|
|
161
|
+
], Client.prototype, "vehicle_links", void 0);
|
|
162
|
+
__decorate([
|
|
163
|
+
(0, typeorm_1.OneToMany)(() => ClientIdentity_1.ClientIdentity, (identity) => identity.client),
|
|
164
|
+
__metadata("design:type", Array)
|
|
165
|
+
], Client.prototype, "identities", void 0);
|
|
166
|
+
__decorate([
|
|
167
|
+
(0, typeorm_1.OneToMany)(() => ClientSession_1.ClientSession, (session) => session.client),
|
|
168
|
+
__metadata("design:type", Array)
|
|
169
|
+
], Client.prototype, "sessions", void 0);
|
|
170
|
+
__decorate([
|
|
171
|
+
(0, typeorm_1.OneToMany)(() => ClientSubscription_1.ClientSubscription, (subscription) => subscription.client),
|
|
172
|
+
__metadata("design:type", Array)
|
|
173
|
+
], Client.prototype, "subscriptions", void 0);
|
|
106
174
|
exports.Client = Client = __decorate([
|
|
107
175
|
(0, typeorm_1.Entity)({
|
|
108
|
-
comment: "Clientes de
|
|
176
|
+
comment: "Clientes de Worklip. Las empresas se vinculan a ellos en company_client.",
|
|
109
177
|
}),
|
|
110
|
-
(0, typeorm_1.Unique)("
|
|
111
|
-
"document",
|
|
112
|
-
"email",
|
|
113
|
-
"phone",
|
|
114
|
-
"company",
|
|
115
|
-
])
|
|
178
|
+
(0, typeorm_1.Unique)("UQ_client_document", ["document_type", "document"])
|
|
116
179
|
], Client);
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ClientIdentity = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
const Client_1 = require("./Client");
|
|
15
|
+
// DOC: Con qué ENTRA el cliente a la app. Va aparte del correo y el celular de contacto: esos
|
|
16
|
+
// los puede escribir mal un asesor y no deben bloquearle la cuenta al dueño real. Solo se
|
|
17
|
+
// guarda lo YA verificado; los códigos viven en Redis con vencimiento.
|
|
18
|
+
let ClientIdentity = class ClientIdentity {
|
|
19
|
+
};
|
|
20
|
+
exports.ClientIdentity = ClientIdentity;
|
|
21
|
+
__decorate([
|
|
22
|
+
(0, typeorm_1.PrimaryGeneratedColumn)({
|
|
23
|
+
type: "int",
|
|
24
|
+
comment: "Número de identificación (ID) único de cada registro.",
|
|
25
|
+
}),
|
|
26
|
+
__metadata("design:type", Number)
|
|
27
|
+
], ClientIdentity.prototype, "id", void 0);
|
|
28
|
+
__decorate([
|
|
29
|
+
(0, typeorm_1.ManyToOne)(() => Client_1.Client, (client) => client.identities, {
|
|
30
|
+
onDelete: "CASCADE",
|
|
31
|
+
onUpdate: "NO ACTION",
|
|
32
|
+
}),
|
|
33
|
+
(0, typeorm_1.JoinColumn)({ name: "client" }),
|
|
34
|
+
__metadata("design:type", Client_1.Client)
|
|
35
|
+
], ClientIdentity.prototype, "client", void 0);
|
|
36
|
+
__decorate([
|
|
37
|
+
(0, typeorm_1.Column)({
|
|
38
|
+
type: "int",
|
|
39
|
+
width: 1,
|
|
40
|
+
comment: "Tipo:\r\n1: Google.\r\n2: Correo electrónico.\r\n3: WhatsApp.",
|
|
41
|
+
}),
|
|
42
|
+
__metadata("design:type", Number)
|
|
43
|
+
], ClientIdentity.prototype, "type", void 0);
|
|
44
|
+
__decorate([
|
|
45
|
+
(0, typeorm_1.Column)({
|
|
46
|
+
type: "varchar",
|
|
47
|
+
length: 255,
|
|
48
|
+
comment: "Valor normalizado: sub de Google, correo en minúscula o celular con indicativo.",
|
|
49
|
+
}),
|
|
50
|
+
__metadata("design:type", String)
|
|
51
|
+
], ClientIdentity.prototype, "value", void 0);
|
|
52
|
+
__decorate([
|
|
53
|
+
(0, typeorm_1.Column)({
|
|
54
|
+
type: "datetime",
|
|
55
|
+
comment: "Cuándo se verificó.",
|
|
56
|
+
default: () => "CURRENT_TIMESTAMP",
|
|
57
|
+
}),
|
|
58
|
+
__metadata("design:type", Date)
|
|
59
|
+
], ClientIdentity.prototype, "verified", void 0);
|
|
60
|
+
__decorate([
|
|
61
|
+
(0, typeorm_1.Column)({
|
|
62
|
+
type: "datetime",
|
|
63
|
+
nullable: true,
|
|
64
|
+
default: null,
|
|
65
|
+
comment: "Último inicio de sesión con esta identidad.",
|
|
66
|
+
}),
|
|
67
|
+
__metadata("design:type", Object)
|
|
68
|
+
], ClientIdentity.prototype, "last_used", void 0);
|
|
69
|
+
__decorate([
|
|
70
|
+
(0, typeorm_1.Column)({
|
|
71
|
+
type: "datetime",
|
|
72
|
+
comment: "Fecha de creación del registro.",
|
|
73
|
+
default: () => "CURRENT_TIMESTAMP",
|
|
74
|
+
}),
|
|
75
|
+
__metadata("design:type", Date)
|
|
76
|
+
], ClientIdentity.prototype, "created", void 0);
|
|
77
|
+
exports.ClientIdentity = ClientIdentity = __decorate([
|
|
78
|
+
(0, typeorm_1.Entity)({
|
|
79
|
+
comment: "Identidades verificadas con las que el cliente inicia sesión.",
|
|
80
|
+
name: "client_identity",
|
|
81
|
+
}),
|
|
82
|
+
(0, typeorm_1.Unique)("UQ_client_identity", ["type", "value"])
|
|
83
|
+
], ClientIdentity);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Country } from "./Country";
|
|
2
|
+
import { ClientPlanLimit } from "./ClientPlanLimit";
|
|
3
|
+
export declare class ClientPlan {
|
|
4
|
+
id: number;
|
|
5
|
+
code: string;
|
|
6
|
+
name: string;
|
|
7
|
+
description: string | null;
|
|
8
|
+
country: Country;
|
|
9
|
+
price: number;
|
|
10
|
+
period: number;
|
|
11
|
+
is_default: number;
|
|
12
|
+
default_country: number | null;
|
|
13
|
+
store_product_ios: string | null;
|
|
14
|
+
store_product_android: string | null;
|
|
15
|
+
status: number;
|
|
16
|
+
created: Date;
|
|
17
|
+
updated: Date | null;
|
|
18
|
+
limits: ClientPlanLimit[];
|
|
19
|
+
}
|