@asumano/worklip-typeorm-db 1.1.96 → 1.1.97

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.
@@ -3,6 +3,8 @@ import { Client } from "./Client";
3
3
  import { Vehicle } from "./Vehicle";
4
4
  import { Workshop } from "./Workshop";
5
5
  import { ServiceOrder } from "./ServiceOrder";
6
+ import { ReminderType } from "./ReminderType";
7
+ import { Template } from "./Template";
6
8
  export declare class Reminder {
7
9
  id: number;
8
10
  workshop: Workshop | null;
@@ -10,12 +12,16 @@ export declare class Reminder {
10
12
  client: Client;
11
13
  associate: Associate | null;
12
14
  service_order: ServiceOrder | null;
15
+ reminder_type: ReminderType | null;
16
+ template: Template | null;
13
17
  title: string;
14
18
  content: string;
15
19
  details: any | null;
16
20
  reminder_date: string;
17
21
  send_via: number;
18
22
  source: number;
23
+ scope: number;
24
+ active_slot: string | null;
19
25
  created: Date;
20
26
  updated: Date | null;
21
27
  status: number;
@@ -16,6 +16,11 @@ const Client_1 = require("./Client");
16
16
  const Vehicle_1 = require("./Vehicle");
17
17
  const Workshop_1 = require("./Workshop");
18
18
  const ServiceOrder_1 = require("./ServiceOrder");
19
+ const ReminderType_1 = require("./ReminderType");
20
+ const Template_1 = require("./Template");
21
+ // DOC: Desde el 2026-09-26 el recordatorio es de la PLACA y no de la visita: lo ve toda la
22
+ // plataforma y lo edita el taller que tiene el vehículo (ver `reminder.rules.ts`).
23
+ // `service_order` queda solo como la visita donde se creó.
19
24
  let Reminder = class Reminder {
20
25
  };
21
26
  exports.Reminder = Reminder;
@@ -63,13 +68,31 @@ __decorate([
63
68
  ], Reminder.prototype, "associate", void 0);
64
69
  __decorate([
65
70
  (0, typeorm_1.ManyToOne)(() => ServiceOrder_1.ServiceOrder, (serviceOrder) => serviceOrder.reminders, {
66
- onDelete: "RESTRICT",
71
+ onDelete: "SET NULL",
67
72
  onUpdate: "NO ACTION",
68
73
  nullable: true,
69
74
  }),
70
75
  (0, typeorm_1.JoinColumn)({ name: "service_order" }),
71
76
  __metadata("design:type", Object)
72
77
  ], Reminder.prototype, "service_order", void 0);
78
+ __decorate([
79
+ (0, typeorm_1.ManyToOne)(() => ReminderType_1.ReminderType, {
80
+ onDelete: "RESTRICT",
81
+ onUpdate: "NO ACTION",
82
+ nullable: true,
83
+ }),
84
+ (0, typeorm_1.JoinColumn)({ name: "reminder_type" }),
85
+ __metadata("design:type", Object)
86
+ ], Reminder.prototype, "reminder_type", void 0);
87
+ __decorate([
88
+ (0, typeorm_1.ManyToOne)(() => Template_1.Template, {
89
+ onDelete: "SET NULL",
90
+ onUpdate: "NO ACTION",
91
+ nullable: true,
92
+ }),
93
+ (0, typeorm_1.JoinColumn)({ name: "template" }),
94
+ __metadata("design:type", Object)
95
+ ], Reminder.prototype, "template", void 0);
73
96
  __decorate([
74
97
  (0, typeorm_1.Column)({
75
98
  type: "varchar",
@@ -119,6 +142,26 @@ __decorate([
119
142
  }),
120
143
  __metadata("design:type", Number)
121
144
  ], Reminder.prototype, "source", void 0);
145
+ __decorate([
146
+ (0, typeorm_1.Column)({
147
+ default: 1,
148
+ type: "int",
149
+ width: 1,
150
+ comment: "Alcance, copiado del tipo:\r\n1: Del vehículo (pasa al nuevo dueño).\r\n2: Del dueño.",
151
+ }),
152
+ __metadata("design:type", Number)
153
+ ], Reminder.prototype, "scope", void 0);
154
+ __decorate([
155
+ (0, typeorm_1.Column)({
156
+ type: "varchar",
157
+ length: 40,
158
+ nullable: true,
159
+ generatedType: "STORED",
160
+ asExpression: "IF(`status` IN (1,4,5) AND `reminder_type` IS NOT NULL, CONCAT(`reminder_type`, ':', IF(`scope` = 2, CONCAT('c', `client`), CONCAT('v', IFNULL(`vehicle`, 0)))), NULL)",
161
+ comment: "Generada: la opción activa del vehículo (o del dueño). Sostiene el UNIQUE.",
162
+ }),
163
+ __metadata("design:type", Object)
164
+ ], Reminder.prototype, "active_slot", void 0);
122
165
  __decorate([
123
166
  (0, typeorm_1.Column)({
124
167
  type: "datetime",
@@ -149,5 +192,6 @@ __decorate([
149
192
  exports.Reminder = Reminder = __decorate([
150
193
  (0, typeorm_1.Entity)({
151
194
  comment: "Recordatorios que se le envían a los clientes.",
152
- })
195
+ }),
196
+ (0, typeorm_1.Unique)("UQ_reminder_active_slot", ["active_slot"])
153
197
  ], Reminder);
@@ -0,0 +1,15 @@
1
+ import { Country } from "./Country";
2
+ import { VehicleType } from "./VehicleType";
3
+ export declare class ReminderType {
4
+ id: number;
5
+ country: Country;
6
+ vehicle_type: VehicleType;
7
+ name: string;
8
+ category: number;
9
+ scope: number;
10
+ position: number;
11
+ details: any | null;
12
+ created: Date;
13
+ updated: Date | null;
14
+ status: number;
15
+ }
@@ -0,0 +1,120 @@
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.ReminderType = void 0;
13
+ const typeorm_1 = require("typeorm");
14
+ const Country_1 = require("./Country");
15
+ const VehicleType_1 = require("./VehicleType");
16
+ // DOC: El catálogo de recordatorios que ofrece Worklip (SOAT, tecnomecánica, cambio de aceite).
17
+ // Es por PAÍS y TIPO DE VEHÍCULO porque los vencimientos cambian de uno a otro; lo
18
+ // administra el panel. Ver `reminder.rules.ts`.
19
+ let ReminderType = class ReminderType {
20
+ };
21
+ exports.ReminderType = ReminderType;
22
+ __decorate([
23
+ (0, typeorm_1.PrimaryGeneratedColumn)({
24
+ type: "int",
25
+ comment: "Número de identificación (ID) único de cada registro.",
26
+ }),
27
+ __metadata("design:type", Number)
28
+ ], ReminderType.prototype, "id", void 0);
29
+ __decorate([
30
+ (0, typeorm_1.ManyToOne)(() => Country_1.Country, {
31
+ onDelete: "RESTRICT",
32
+ onUpdate: "NO ACTION",
33
+ }),
34
+ (0, typeorm_1.JoinColumn)({ name: "country" }),
35
+ __metadata("design:type", Country_1.Country)
36
+ ], ReminderType.prototype, "country", void 0);
37
+ __decorate([
38
+ (0, typeorm_1.ManyToOne)(() => VehicleType_1.VehicleType, {
39
+ onDelete: "RESTRICT",
40
+ onUpdate: "NO ACTION",
41
+ }),
42
+ (0, typeorm_1.JoinColumn)({ name: "vehicle_type" }),
43
+ __metadata("design:type", VehicleType_1.VehicleType)
44
+ ], ReminderType.prototype, "vehicle_type", void 0);
45
+ __decorate([
46
+ (0, typeorm_1.Column)({
47
+ type: "varchar",
48
+ length: 100,
49
+ comment: "Nombre del recordatorio. Es el título que sale en el mensaje.",
50
+ }),
51
+ __metadata("design:type", String)
52
+ ], ReminderType.prototype, "name", void 0);
53
+ __decorate([
54
+ (0, typeorm_1.Column)({
55
+ default: 1,
56
+ type: "int",
57
+ width: 1,
58
+ comment: "Categoría:\r\n1: Vencimiento (SOAT, tecnomecánica).\r\n2: Mantenimiento.",
59
+ }),
60
+ __metadata("design:type", Number)
61
+ ], ReminderType.prototype, "category", void 0);
62
+ __decorate([
63
+ (0, typeorm_1.Column)({
64
+ default: 1,
65
+ type: "int",
66
+ width: 1,
67
+ comment: "Alcance:\r\n1: Del vehículo (pasa al nuevo dueño).\r\n2: Del dueño (se queda con la persona).",
68
+ }),
69
+ __metadata("design:type", Number)
70
+ ], ReminderType.prototype, "scope", void 0);
71
+ __decorate([
72
+ (0, typeorm_1.Column)({
73
+ default: 0,
74
+ type: "int",
75
+ comment: "Orden en que se muestra en la lista.",
76
+ }),
77
+ __metadata("design:type", Number)
78
+ ], ReminderType.prototype, "position", void 0);
79
+ __decorate([
80
+ (0, typeorm_1.Column)({
81
+ type: "json",
82
+ nullable: true,
83
+ default: null,
84
+ comment: "Campo de tipo json para almacenar datos que se necesitan.",
85
+ }),
86
+ __metadata("design:type", Object)
87
+ ], ReminderType.prototype, "details", void 0);
88
+ __decorate([
89
+ (0, typeorm_1.Column)({
90
+ type: "datetime",
91
+ comment: "Fecha de creación del registro.",
92
+ default: () => "CURRENT_TIMESTAMP",
93
+ }),
94
+ __metadata("design:type", Date)
95
+ ], ReminderType.prototype, "created", void 0);
96
+ __decorate([
97
+ (0, typeorm_1.Column)({
98
+ type: "datetime",
99
+ nullable: true,
100
+ default: null,
101
+ comment: "Fecha de actualización del registro.",
102
+ onUpdate: "CURRENT_TIMESTAMP",
103
+ }),
104
+ __metadata("design:type", Object)
105
+ ], ReminderType.prototype, "updated", void 0);
106
+ __decorate([
107
+ (0, typeorm_1.Column)({
108
+ default: 1,
109
+ type: "int",
110
+ width: 1,
111
+ comment: "Estado:\r\n1. Activo: se ofrece al crear recordatorios.\r\n0. Inactivo: ya no se ofrece.",
112
+ }),
113
+ __metadata("design:type", Number)
114
+ ], ReminderType.prototype, "status", void 0);
115
+ exports.ReminderType = ReminderType = __decorate([
116
+ (0, typeorm_1.Entity)("reminder_type", {
117
+ comment: "Catálogo de tipos de recordatorio por país y tipo de vehículo.",
118
+ }),
119
+ (0, typeorm_1.Unique)("unique_country_vehicle_type_name", ["country", "vehicle_type", "name"])
120
+ ], ReminderType);
@@ -30,6 +30,7 @@ export declare class ServiceOrder {
30
30
  created: Date;
31
31
  updated: Date | null;
32
32
  status: number;
33
+ finished: Date | null;
33
34
  workboard_status: WorkboardStatus | null;
34
35
  workboard_changed: Date | null;
35
36
  promised_date: Date | null;
@@ -178,6 +178,15 @@ __decorate([
178
178
  }),
179
179
  __metadata("design:type", Number)
180
180
  ], ServiceOrder.prototype, "status", void 0);
181
+ __decorate([
182
+ (0, typeorm_1.Column)({
183
+ type: "datetime",
184
+ nullable: true,
185
+ default: null,
186
+ comment: "Cuándo se finalizó la visita. NULL mientras no esté finalizada.",
187
+ }),
188
+ __metadata("design:type", Object)
189
+ ], ServiceOrder.prototype, "finished", void 0);
181
190
  __decorate([
182
191
  (0, typeorm_1.ManyToOne)(() => WorkboardStatus_1.WorkboardStatus, (status) => status.service_orders, {
183
192
  onDelete: "RESTRICT",
@@ -22,6 +22,7 @@ export { TemplateSection } from "./entities/TemplateSection";
22
22
  export { ServiceOrder } from "./entities/ServiceOrder";
23
23
  export { ServiceOrderHistory } from "./entities/ServiceOrderHistory";
24
24
  export { Reminder } from "./entities/Reminder";
25
+ export { ReminderType } from "./entities/ReminderType";
25
26
  export { Appointment } from "./entities/Appointment";
26
27
  export { CompanyClient } from "./entities/CompanyClient";
27
28
  export { CompanyVehicle } from "./entities/CompanyVehicle";
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CompanySubscription = exports.SubscriptionPlan = exports.CountryHoliday = exports.CompanyVehicleType = exports.BrandVehicleType = exports.CompanyBrand = exports.VehicleType = exports.MasterSection = exports.MasterPermission = exports.MasterRole = exports.MasterPlatform = exports.MasterPasswordReset = exports.AssociatePasswordReset = exports.AssociateSection = exports.AssociatePermission = exports.AssociateRole = exports.AssociatePlatform = exports.ClientSubscription = exports.ClientPlanLimit = exports.ClientPlan = exports.ClientSession = exports.ClientIdentity = exports.ClientVehicle = exports.CompanyVehicle = exports.CompanyClient = exports.Appointment = exports.Reminder = exports.ServiceOrderHistory = exports.ServiceOrder = exports.TemplateSection = exports.SectionItem = exports.Section = exports.Template = exports.Workshop = exports.GlobalTemplateSection = exports.GlobalSectionItem = exports.GlobalSection = exports.GlobalTemplate = exports.AssociateSession = exports.MasterSession = exports.Associate = exports.Client = exports.Master = exports.Vehicle = exports.Brand = exports.Company = exports.City = exports.Region = exports.WhatsappLine = exports.Country = void 0;
4
- exports.GlobalSectionItems = exports.GlobalSections = exports.GlobalTemplates = exports.SubscriptionAddonTemplates = exports.SubscriptionPlans = exports.Masters = exports.Companies = exports.WorkshopsByAssociate = exports.Workshops = exports.SectionItems = exports.Sections = exports.Templates = exports.Reminders = exports.Vehicles = exports.Clients = exports.ServicesOrder = exports.Associates = exports.WorkshopReader = exports.AssociateTag = exports.WorkshopTag = exports.WorkboardEvent = exports.ServiceOrderStage = exports.WorkboardStatus = exports.CompanyDiscount = exports.DiscountCode = exports.PlanFeature = exports.CompanyFeature = exports.Feature = exports.UsageAlert = exports.SubscriptionAddonTemplate = exports.PaymentTransaction = exports.BillingInvoice = exports.EmailSuppression = exports.EmailLog = exports.WhatsappLog = exports.ServiceOrderApproval = exports.MediaFile = exports.BillingUsageSnapshot = exports.PaymentMethod = exports.SubscriptionAddon = void 0;
3
+ exports.SubscriptionPlan = exports.CountryHoliday = exports.CompanyVehicleType = exports.BrandVehicleType = exports.CompanyBrand = exports.VehicleType = exports.MasterSection = exports.MasterPermission = exports.MasterRole = exports.MasterPlatform = exports.MasterPasswordReset = exports.AssociatePasswordReset = exports.AssociateSection = exports.AssociatePermission = exports.AssociateRole = exports.AssociatePlatform = exports.ClientSubscription = exports.ClientPlanLimit = exports.ClientPlan = exports.ClientSession = exports.ClientIdentity = exports.ClientVehicle = exports.CompanyVehicle = exports.CompanyClient = exports.Appointment = exports.ReminderType = exports.Reminder = exports.ServiceOrderHistory = exports.ServiceOrder = exports.TemplateSection = exports.SectionItem = exports.Section = exports.Template = exports.Workshop = exports.GlobalTemplateSection = exports.GlobalSectionItem = exports.GlobalSection = exports.GlobalTemplate = exports.AssociateSession = exports.MasterSession = exports.Associate = exports.Client = exports.Master = exports.Vehicle = exports.Brand = exports.Company = exports.City = exports.Region = exports.WhatsappLine = exports.Country = void 0;
4
+ exports.GlobalSectionItems = exports.GlobalSections = exports.GlobalTemplates = exports.SubscriptionAddonTemplates = exports.SubscriptionPlans = exports.Masters = exports.Companies = exports.WorkshopsByAssociate = exports.Workshops = exports.SectionItems = exports.Sections = exports.Templates = exports.Reminders = exports.Vehicles = exports.Clients = exports.ServicesOrder = exports.Associates = exports.WorkshopReader = exports.AssociateTag = exports.WorkshopTag = exports.WorkboardEvent = exports.ServiceOrderStage = exports.WorkboardStatus = exports.CompanyDiscount = exports.DiscountCode = exports.PlanFeature = exports.CompanyFeature = exports.Feature = exports.UsageAlert = exports.SubscriptionAddonTemplate = exports.PaymentTransaction = exports.BillingInvoice = exports.EmailSuppression = exports.EmailLog = exports.WhatsappLog = exports.ServiceOrderApproval = exports.MediaFile = exports.BillingUsageSnapshot = exports.PaymentMethod = exports.SubscriptionAddon = exports.CompanySubscription = void 0;
5
5
  var Country_1 = require("./entities/Country");
6
6
  Object.defineProperty(exports, "Country", { enumerable: true, get: function () { return Country_1.Country; } });
7
7
  var WhatsappLine_1 = require("./entities/WhatsappLine");
@@ -52,6 +52,8 @@ var ServiceOrderHistory_1 = require("./entities/ServiceOrderHistory");
52
52
  Object.defineProperty(exports, "ServiceOrderHistory", { enumerable: true, get: function () { return ServiceOrderHistory_1.ServiceOrderHistory; } });
53
53
  var Reminder_1 = require("./entities/Reminder");
54
54
  Object.defineProperty(exports, "Reminder", { enumerable: true, get: function () { return Reminder_1.Reminder; } });
55
+ var ReminderType_1 = require("./entities/ReminderType");
56
+ Object.defineProperty(exports, "ReminderType", { enumerable: true, get: function () { return ReminderType_1.ReminderType; } });
55
57
  // DOC: La CITA que el cliente agenda antes de traer el carro. Tabla propia y no un estado de
56
58
  // la visita: la visita consume cupo del plan y quema consecutivo. Ver la entidad.
57
59
  var Appointment_1 = require("./entities/Appointment");
package/dist/index.d.ts CHANGED
@@ -14,6 +14,8 @@ export * from "./workshop.schedule";
14
14
  export * from "./booking.rules";
15
15
  export * from "./client.link.rules";
16
16
  export * from "./client.plan.rules";
17
+ export * from "./reminder.rules";
18
+ export * from "./vehicle.type.rules";
17
19
  export declare function createDataBaseSource(): DataSource;
18
20
  export declare function showEntityName<T extends ObjectLiteral>(entity: EntityTarget<T>): Promise<Repository<T>>;
19
21
  export declare function callStoredProcedureName(storedProcedure: any, elements: any): Promise<any>;
package/dist/index.js CHANGED
@@ -99,6 +99,12 @@ __exportStar(require("./client.link.rules"), exports);
99
99
  // DOC: Planes del cliente: los códigos de límite, qué suscripción vale y cuáles recordatorios
100
100
  // avisan. El API frena, la app pinta el candado y el panel edita: una sola cuenta.
101
101
  __exportStar(require("./client.plan.rules"), exports);
102
+ // DOC: Recordatorios por placa: quién tiene el vehículo, qué opción ocupa y quién ve o edita.
103
+ // El API frena y el portal esconde los botones: una sola regla.
104
+ __exportStar(require("./reminder.rules"), exports);
105
+ // DOC: Lo que vive en `vehicle_type.details` (placa, kilometraje y color). El panel lo edita y los
106
+ // dos fronts pintan el tag del tipo con la misma lectura.
107
+ __exportStar(require("./vehicle.type.rules"), exports);
102
108
  let connection = null;
103
109
  // DOC: Inicialización en curso. Se memoriza la PROMESA y no el resultado porque el patrón
104
110
  // "si no está inicializada, inicialízala" tiene una carrera en el arranque en frío: dos
@@ -0,0 +1,46 @@
1
+ export declare const REMINDER_TYPE_CATEGORY: {
2
+ readonly EXPIRATION: 1;
3
+ readonly MAINTENANCE: 2;
4
+ };
5
+ export declare const REMINDER_SCOPE: {
6
+ readonly VEHICLE: 1;
7
+ readonly OWNER: 2;
8
+ };
9
+ export declare const REMINDER_SOURCE: {
10
+ readonly WORKSHOP: 1;
11
+ readonly CLIENT: 2;
12
+ };
13
+ export declare const REMINDER_ACTIVE_STATUSES: readonly [1, 4, 5];
14
+ export declare const CUSTODY_DAYS_AFTER_FINISH = 3;
15
+ export declare const CUSTODY_VISIT_STATUSES: readonly [1, 2];
16
+ export interface ICustodyVisit {
17
+ status: number;
18
+ finished: Date | string | null;
19
+ }
20
+ /**
21
+ * DOC: ¿La visita MÁS RECIENTE del vehículo le da la custodia a su taller? Abierta, siempre (el
22
+ * carro sigue ahí); finalizada, durante `CUSTODY_DAYS_AFTER_FINISH` días. Quien llama ya
23
+ * escogió la más reciente: la custodia es de UN solo taller.
24
+ */
25
+ export declare const visitGivesCustody: (visit: ICustodyVisit | null | undefined, now?: Date) => boolean;
26
+ export interface IReminderSlotInput {
27
+ reminder_type: number | null | undefined;
28
+ scope: number | null | undefined;
29
+ client: number | null | undefined;
30
+ vehicle: number | null | undefined;
31
+ status: number;
32
+ }
33
+ /**
34
+ * DOC: La opción que ocupa el recordatorio, igual a la columna generada `active_slot`. NULL si
35
+ * no ocupa nada (entregado, cancelado o «Otro»). El del dueño va por cliente: la licencia es
36
+ * una sola aunque tenga tres carros.
37
+ */
38
+ export declare const reminderSlot: (r: IReminderSlotInput) => string | null;
39
+ export interface IReminderAccessInput {
40
+ company: number;
41
+ custodyCompany: number | null;
42
+ reminderCompany: number | null;
43
+ source: number;
44
+ }
45
+ export declare const canCompanySeeReminder: (a: IReminderAccessInput) => boolean;
46
+ export declare const canCompanyEditReminder: (a: IReminderAccessInput) => boolean;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ // DOC: Reglas de los recordatorios POR PLACA (2026-09-26). El recordatorio es del vehículo y lo
3
+ // ve toda la plataforma; lo toca el taller que TIENE el vehículo. El API las hace cumplir
4
+ // y el portal esconde los botones con ellas: separadas, la pantalla ofrecería editar lo
5
+ // que el servidor rechaza.
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.canCompanyEditReminder = exports.canCompanySeeReminder = exports.reminderSlot = exports.visitGivesCustody = exports.CUSTODY_VISIT_STATUSES = exports.CUSTODY_DAYS_AFTER_FINISH = exports.REMINDER_ACTIVE_STATUSES = exports.REMINDER_SOURCE = exports.REMINDER_SCOPE = exports.REMINDER_TYPE_CATEGORY = void 0;
10
+ // DOC: `reminder_type.category`. Solo agrupa la lista; no cambia ninguna regla.
11
+ exports.REMINDER_TYPE_CATEGORY = {
12
+ EXPIRATION: 1,
13
+ MAINTENANCE: 2,
14
+ };
15
+ // DOC: `reminder_type.scope` (copiado en `reminder.scope`). El del vehículo pasa al nuevo dueño
16
+ // al venderlo; el del dueño (la licencia) se queda con la persona.
17
+ exports.REMINDER_SCOPE = {
18
+ VEHICLE: 1,
19
+ OWNER: 2,
20
+ };
21
+ // DOC: `reminder.source`. Lo que crea el cliente desde la app es solo suyo.
22
+ exports.REMINDER_SOURCE = {
23
+ WORKSHOP: 1,
24
+ CLIENT: 2,
25
+ };
26
+ // DOC: Estados que ocupan la opción (pendiente, con error y agendado). Lo entregado y lo
27
+ // cancelado es historial y no bloquea uno nuevo. Debe coincidir con `reminder.active_slot`.
28
+ exports.REMINDER_ACTIVE_STATUSES = [1, 4, 5];
29
+ // DOC: Días que el taller conserva el vehículo después de finalizar la visita. Con uno solo, lo
30
+ // que se entrega el viernes en la tarde ya no se puede agendar el lunes.
31
+ exports.CUSTODY_DAYS_AFTER_FINISH = 3;
32
+ // DOC: Estados de visita que cuentan para la custodia: en edición y finalizada. La cancelada y
33
+ // la descartada no: el vehículo no se quedó ahí.
34
+ exports.CUSTODY_VISIT_STATUSES = [1, 2];
35
+ /**
36
+ * DOC: ¿La visita MÁS RECIENTE del vehículo le da la custodia a su taller? Abierta, siempre (el
37
+ * carro sigue ahí); finalizada, durante `CUSTODY_DAYS_AFTER_FINISH` días. Quien llama ya
38
+ * escogió la más reciente: la custodia es de UN solo taller.
39
+ */
40
+ const visitGivesCustody = (visit, now = new Date()) => {
41
+ if (!visit)
42
+ return false;
43
+ if (visit.status === 1)
44
+ return true;
45
+ if (visit.status !== 2 || !visit.finished)
46
+ return false;
47
+ const finished = new Date(visit.finished).getTime();
48
+ if (Number.isNaN(finished))
49
+ return false;
50
+ return now.getTime() - finished <= exports.CUSTODY_DAYS_AFTER_FINISH * 24 * 60 * 60 * 1000;
51
+ };
52
+ exports.visitGivesCustody = visitGivesCustody;
53
+ /**
54
+ * DOC: La opción que ocupa el recordatorio, igual a la columna generada `active_slot`. NULL si
55
+ * no ocupa nada (entregado, cancelado o «Otro»). El del dueño va por cliente: la licencia es
56
+ * una sola aunque tenga tres carros.
57
+ */
58
+ const reminderSlot = (r) => {
59
+ if (!r.reminder_type)
60
+ return null;
61
+ if (!exports.REMINDER_ACTIVE_STATUSES.includes(r.status))
62
+ return null;
63
+ return r.scope === exports.REMINDER_SCOPE.OWNER
64
+ ? `${r.reminder_type}:c${r.client ?? 0}`
65
+ : `${r.reminder_type}:v${r.vehicle ?? 0}`;
66
+ };
67
+ exports.reminderSlot = reminderSlot;
68
+ // DOC: Ver: quien tiene el vehículo ve todo; los demás, solo lo suyo.
69
+ const canCompanySeeReminder = (a) => a.company > 0 &&
70
+ (a.custodyCompany === a.company || a.reminderCompany === a.company);
71
+ exports.canCompanySeeReminder = canCompanySeeReminder;
72
+ // DOC: Editar, cancelar o borrar: igual que ver, salvo lo que creó el cliente, que es solo suyo.
73
+ const canCompanyEditReminder = (a) => a.source !== exports.REMINDER_SOURCE.CLIENT && (0, exports.canCompanySeeReminder)(a);
74
+ exports.canCompanyEditReminder = canCompanyEditReminder;
@@ -0,0 +1,15 @@
1
+ export declare const VEHICLE_MILEAGE: {
2
+ readonly REQUIRED: "required";
3
+ readonly OPTIONAL: "optional";
4
+ };
5
+ export type TVehicleMileage = (typeof VEHICLE_MILEAGE)[keyof typeof VEHICLE_MILEAGE];
6
+ export interface IVehicleTypeDetails {
7
+ plate?: string | null;
8
+ mileage?: TVehicleMileage | null;
9
+ color?: string | null;
10
+ [key: string]: unknown;
11
+ }
12
+ export declare const VEHICLE_TYPE_DEFAULT_COLOR = "#64748b";
13
+ export declare const normalizeHexColor: (value: unknown) => string | null;
14
+ export declare const getVehicleTypeColor: (details: IVehicleTypeDetails | null | undefined) => string;
15
+ export declare const isValidPlateMask: (mask: unknown) => boolean;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ // DOC: Lo que vive en `vehicle_type.details`: la máscara de la placa, si el kilometraje es
3
+ // obligatorio y el COLOR con que se pinta el tipo en tablas, selectores y filtros. Lo edita
4
+ // el panel y lo leen los dos fronts: una sola lectura para que el color no salga distinto.
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.isValidPlateMask = exports.getVehicleTypeColor = exports.normalizeHexColor = exports.VEHICLE_TYPE_DEFAULT_COLOR = exports.VEHICLE_MILEAGE = void 0;
9
+ exports.VEHICLE_MILEAGE = {
10
+ REQUIRED: "required",
11
+ OPTIONAL: "optional",
12
+ };
13
+ // DOC: El gris de un tipo sin color. Neutro a propósito: no compite con los que sí tienen.
14
+ exports.VEHICLE_TYPE_DEFAULT_COLOR = "#64748b";
15
+ const HEX = /^#([0-9a-f]{6})$/i;
16
+ // DOC: "#rgb", "rrggbb" o "#RRGGBB" -> "#rrggbb"; null si no es un color.
17
+ const normalizeHexColor = (value) => {
18
+ const raw = String(value ?? "").trim();
19
+ if (!raw)
20
+ return null;
21
+ const withHash = raw.startsWith("#") ? raw : `#${raw}`;
22
+ const short = /^#([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec(withHash);
23
+ const full = short ? `#${short[1]}${short[1]}${short[2]}${short[2]}${short[3]}${short[3]}` : withHash;
24
+ return HEX.test(full) ? full.toLowerCase() : null;
25
+ };
26
+ exports.normalizeHexColor = normalizeHexColor;
27
+ const getVehicleTypeColor = (details) => (0, exports.normalizeHexColor)(details?.color) ?? exports.VEHICLE_TYPE_DEFAULT_COLOR;
28
+ exports.getVehicleTypeColor = getVehicleTypeColor;
29
+ // DOC: Una máscara válida: solo `a`, `9` y separadores, entre 3 y 12 caracteres, con al menos
30
+ // una letra o un número. Evita guardar una máscara que haga imposible escribir la placa.
31
+ const isValidPlateMask = (mask) => {
32
+ const value = String(mask ?? "");
33
+ return /^[a9\- ]{3,12}$/.test(value) && /[a9]/.test(value);
34
+ };
35
+ exports.isValidPlateMask = isValidPlateMask;
@@ -1,6 +1,6 @@
1
1
  export declare class Reminders {
2
2
  id: number;
3
- workshop: number;
3
+ workshop: number | null;
4
4
  vehicle: number;
5
5
  client: number;
6
6
  associate: number | null;
@@ -10,22 +10,31 @@ export declare class Reminders {
10
10
  details: any | null;
11
11
  reminder_date: string;
12
12
  send_via: number;
13
+ source: number;
14
+ scope: number;
15
+ reminder_type: number | null;
16
+ template: number | null;
13
17
  created: Date;
14
18
  updated: Date | null;
15
19
  status: number;
16
- workshop_id: number;
17
- workshop_company: number;
18
- workshop_name: string;
19
- workshop_code: string;
20
+ workshop_id: number | null;
21
+ workshop_company: number | null;
22
+ workshop_name: string | null;
23
+ workshop_code: string | null;
20
24
  workshop_details: any | null;
21
- workshop_address: string;
22
- workshop_latitude: number;
23
- workshop_longitude: number;
24
- workshop_created: Date;
25
+ workshop_address: string | null;
26
+ workshop_latitude: number | null;
27
+ workshop_longitude: number | null;
28
+ workshop_created: Date | null;
25
29
  workshop_updated: Date | null;
26
- workshop_status: number;
30
+ workshop_status: number | null;
31
+ reminder_type_name: string | null;
32
+ reminder_type_category: number | null;
33
+ template_name: string | null;
27
34
  vehicle_id: number | null;
28
35
  vehicle_plate: string | null;
36
+ vehicle_serial: string | null;
37
+ vehicle_type: number | null;
29
38
  vehicle_brand: number | null;
30
39
  vehicle_mileage: number | null;
31
40
  vehicle_model: number | null;
@@ -20,7 +20,7 @@ __decorate([
20
20
  ], Reminders.prototype, "id", void 0);
21
21
  __decorate([
22
22
  (0, typeorm_1.ViewColumn)(),
23
- __metadata("design:type", Number)
23
+ __metadata("design:type", Object)
24
24
  ], Reminders.prototype, "workshop", void 0);
25
25
  __decorate([
26
26
  (0, typeorm_1.ViewColumn)(),
@@ -58,6 +58,22 @@ __decorate([
58
58
  (0, typeorm_1.ViewColumn)(),
59
59
  __metadata("design:type", Number)
60
60
  ], Reminders.prototype, "send_via", void 0);
61
+ __decorate([
62
+ (0, typeorm_1.ViewColumn)(),
63
+ __metadata("design:type", Number)
64
+ ], Reminders.prototype, "source", void 0);
65
+ __decorate([
66
+ (0, typeorm_1.ViewColumn)(),
67
+ __metadata("design:type", Number)
68
+ ], Reminders.prototype, "scope", void 0);
69
+ __decorate([
70
+ (0, typeorm_1.ViewColumn)(),
71
+ __metadata("design:type", Object)
72
+ ], Reminders.prototype, "reminder_type", void 0);
73
+ __decorate([
74
+ (0, typeorm_1.ViewColumn)(),
75
+ __metadata("design:type", Object)
76
+ ], Reminders.prototype, "template", void 0);
61
77
  __decorate([
62
78
  (0, typeorm_1.ViewColumn)(),
63
79
  __metadata("design:type", Date)
@@ -72,19 +88,19 @@ __decorate([
72
88
  ], Reminders.prototype, "status", void 0);
73
89
  __decorate([
74
90
  (0, typeorm_1.ViewColumn)(),
75
- __metadata("design:type", Number)
91
+ __metadata("design:type", Object)
76
92
  ], Reminders.prototype, "workshop_id", void 0);
77
93
  __decorate([
78
94
  (0, typeorm_1.ViewColumn)(),
79
- __metadata("design:type", Number)
95
+ __metadata("design:type", Object)
80
96
  ], Reminders.prototype, "workshop_company", void 0);
81
97
  __decorate([
82
98
  (0, typeorm_1.ViewColumn)(),
83
- __metadata("design:type", String)
99
+ __metadata("design:type", Object)
84
100
  ], Reminders.prototype, "workshop_name", void 0);
85
101
  __decorate([
86
102
  (0, typeorm_1.ViewColumn)(),
87
- __metadata("design:type", String)
103
+ __metadata("design:type", Object)
88
104
  ], Reminders.prototype, "workshop_code", void 0);
89
105
  __decorate([
90
106
  (0, typeorm_1.ViewColumn)(),
@@ -92,19 +108,19 @@ __decorate([
92
108
  ], Reminders.prototype, "workshop_details", void 0);
93
109
  __decorate([
94
110
  (0, typeorm_1.ViewColumn)(),
95
- __metadata("design:type", String)
111
+ __metadata("design:type", Object)
96
112
  ], Reminders.prototype, "workshop_address", void 0);
97
113
  __decorate([
98
114
  (0, typeorm_1.ViewColumn)(),
99
- __metadata("design:type", Number)
115
+ __metadata("design:type", Object)
100
116
  ], Reminders.prototype, "workshop_latitude", void 0);
101
117
  __decorate([
102
118
  (0, typeorm_1.ViewColumn)(),
103
- __metadata("design:type", Number)
119
+ __metadata("design:type", Object)
104
120
  ], Reminders.prototype, "workshop_longitude", void 0);
105
121
  __decorate([
106
122
  (0, typeorm_1.ViewColumn)(),
107
- __metadata("design:type", Date)
123
+ __metadata("design:type", Object)
108
124
  ], Reminders.prototype, "workshop_created", void 0);
109
125
  __decorate([
110
126
  (0, typeorm_1.ViewColumn)(),
@@ -112,8 +128,20 @@ __decorate([
112
128
  ], Reminders.prototype, "workshop_updated", void 0);
113
129
  __decorate([
114
130
  (0, typeorm_1.ViewColumn)(),
115
- __metadata("design:type", Number)
131
+ __metadata("design:type", Object)
116
132
  ], Reminders.prototype, "workshop_status", void 0);
133
+ __decorate([
134
+ (0, typeorm_1.ViewColumn)(),
135
+ __metadata("design:type", Object)
136
+ ], Reminders.prototype, "reminder_type_name", void 0);
137
+ __decorate([
138
+ (0, typeorm_1.ViewColumn)(),
139
+ __metadata("design:type", Object)
140
+ ], Reminders.prototype, "reminder_type_category", void 0);
141
+ __decorate([
142
+ (0, typeorm_1.ViewColumn)(),
143
+ __metadata("design:type", Object)
144
+ ], Reminders.prototype, "template_name", void 0);
117
145
  __decorate([
118
146
  (0, typeorm_1.ViewColumn)(),
119
147
  __metadata("design:type", Object)
@@ -122,6 +150,14 @@ __decorate([
122
150
  (0, typeorm_1.ViewColumn)(),
123
151
  __metadata("design:type", Object)
124
152
  ], Reminders.prototype, "vehicle_plate", void 0);
153
+ __decorate([
154
+ (0, typeorm_1.ViewColumn)(),
155
+ __metadata("design:type", Object)
156
+ ], Reminders.prototype, "vehicle_serial", void 0);
157
+ __decorate([
158
+ (0, typeorm_1.ViewColumn)(),
159
+ __metadata("design:type", Object)
160
+ ], Reminders.prototype, "vehicle_type", void 0);
125
161
  __decorate([
126
162
  (0, typeorm_1.ViewColumn)(),
127
163
  __metadata("design:type", Object)
@@ -21,25 +21,6 @@ export interface IVisitEvidence {
21
21
  purged?: boolean;
22
22
  purged_at?: string;
23
23
  }
24
- /**
25
- * DOC: El recordatorio de un ítem, tal como queda en el JSON de la visita.
26
- *
27
- * Ya NO hay aprobación del cliente. Hasta el 2026-09-01 la fecha era una PROPUESTA: el
28
- * cliente la aceptaba o la rechazaba en su informe y solo lo aceptado entraba a la agenda.
29
- * Se quitó: ahora el taller pone la fecha y el recordatorio queda creado en el mismo acto.
30
- * El cliente lo VE en su informe, pero no decide.
31
- *
32
- * Por eso este bloque ya no guarda una respuesta, solo el HILO con la agenda: el id de la
33
- * fila de `reminder` que se creó. Es lo que permite moverla si el taller cambia la fecha y
34
- * borrarla si la quita — sin él, al cliente le llegaría un recordatorio de algo que el
35
- * taller ya deshizo.
36
- *
37
- * Lo escribe el API, nunca el navegador (ver `syncItemReminders`, que es regla de servidor).
38
- */
39
- export interface IVisitItemReminder {
40
- reminder_id?: number | null;
41
- created_at?: number | null;
42
- }
43
24
  export interface IVisitItem {
44
25
  id: string;
45
26
  template_item_id: number | null;
@@ -49,8 +30,6 @@ export interface IVisitItem {
49
30
  visible: boolean;
50
31
  status: TItemStatus;
51
32
  comments: string;
52
- appointment_reminder?: string | Date | null;
53
- reminder?: IVisitItemReminder | null;
54
33
  costs: IVisitCosts | null;
55
34
  evidence: IVisitEvidence[];
56
35
  order: number;
@@ -316,10 +316,6 @@ const isVisitEmpty = (visit) => {
316
316
  // DOC: Un costo en cero no es una cotización: es el valor por defecto del campo.
317
317
  if (Number(item.costs?.total) > 0)
318
318
  return false;
319
- // DOC: La FECHA es lo que crea el recordatorio; `reminder` solo guarda la respuesta del
320
- // cliente y lo escribe el API.
321
- if (item.appointment_reminder)
322
- return false;
323
319
  }
324
320
  }
325
321
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asumano/worklip-typeorm-db",
3
- "version": "1.1.96",
3
+ "version": "1.1.97",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },