@tmlmobilidade/interfaces 20251222.1552.52 → 20251222.1756.6

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.
@@ -247,6 +247,18 @@ export class MongoCollectionClass {
247
247
  throw new Error('No schema defined for insert operation. This is either an internal interface error or you should pass unsafe=true to the insert operation.');
248
248
  // Validate the document against the create schema
249
249
  parsedDocument = this.createSchema.parse(parsedDocument);
250
+ // Add the missing default fields, if present in the original document.
251
+ // The schema might have omitted these fields, so we need to add them back.
252
+ if (doc._id)
253
+ parsedDocument._id = doc._id;
254
+ if (doc.created_at)
255
+ parsedDocument.created_at = doc.created_at;
256
+ if (doc.created_by)
257
+ parsedDocument.created_by = doc.created_by;
258
+ if (doc.updated_at)
259
+ parsedDocument.updated_at = doc.updated_at;
260
+ if (doc.updated_by)
261
+ parsedDocument.updated_by = doc.updated_by;
250
262
  }
251
263
  catch (error) {
252
264
  throw new HttpException(HttpStatus.BAD_REQUEST, error.message, { cause: error });
@@ -62,9 +62,7 @@ declare class AgenciesClass extends MongoCollectionClass<Agency, CreateAgencyDto
62
62
  }>>;
63
63
  protected getCollectionIndexes(): IndexDescription[];
64
64
  protected getCollectionName(): string;
65
- protected getCreateSchema(): z.ZodSchema;
66
65
  protected getEnvName(): string;
67
- protected getUpdateSchema(): z.ZodSchema;
68
66
  }
69
67
  export declare const agencies: AgenciesClass;
70
68
  export {};
@@ -1,11 +1,11 @@
1
1
  /* * */
2
2
  import { MongoCollectionClass } from '../../common/mongo-collection.js';
3
- import { AgencySchema, UpdateAgencySchema } from '@tmlmobilidade/types';
3
+ import { CreateAgencySchema, UpdateAgencySchema } from '@tmlmobilidade/types';
4
4
  import { AsyncSingletonProxy } from '@tmlmobilidade/utils';
5
5
  /* * */
6
6
  class AgenciesClass extends MongoCollectionClass {
7
7
  static _instance;
8
- createSchema = AgencySchema;
8
+ createSchema = CreateAgencySchema;
9
9
  updateSchema = UpdateAgencySchema;
10
10
  constructor() {
11
11
  super();
@@ -34,15 +34,9 @@ class AgenciesClass extends MongoCollectionClass {
34
34
  getCollectionName() {
35
35
  return 'agencies';
36
36
  }
37
- getCreateSchema() {
38
- return AgencySchema;
39
- }
40
37
  getEnvName() {
41
38
  return 'DATABASE_URI';
42
39
  }
43
- getUpdateSchema() {
44
- return UpdateAgencySchema;
45
- }
46
40
  }
47
41
  /* * */
48
42
  export const agencies = AsyncSingletonProxy(AgenciesClass);
@@ -1,5 +1,5 @@
1
1
  import { MongoCollectionClass } from '../../common/mongo-collection.js';
2
- import { Alert, CreateAlertDto, UpdateAlertDto } from '@tmlmobilidade/types';
2
+ import { type Alert, type CreateAlertDto, type UpdateAlertDto } from '@tmlmobilidade/types';
3
3
  import { IndexDescription } from 'mongodb';
4
4
  import { z } from 'zod';
5
5
  declare class AlertsClass extends MongoCollectionClass<Alert, CreateAlertDto, UpdateAlertDto> {
@@ -1,11 +1,11 @@
1
1
  /* * */
2
2
  import { MongoCollectionClass } from '../../common/mongo-collection.js';
3
- import { AlertSchema, UpdateAlertSchema } from '@tmlmobilidade/types';
3
+ import { CreateAlertSchema, UpdateAlertSchema } from '@tmlmobilidade/types';
4
4
  import { AsyncSingletonProxy } from '@tmlmobilidade/utils';
5
5
  /* * */
6
6
  class AlertsClass extends MongoCollectionClass {
7
7
  static _instance;
8
- createSchema = AlertSchema;
8
+ createSchema = CreateAlertSchema;
9
9
  updateSchema = UpdateAlertSchema;
10
10
  constructor() {
11
11
  super();
@@ -1,11 +1,11 @@
1
1
  /* * */
2
2
  import { MongoCollectionClass } from '../../common/mongo-collection.js';
3
- import { PermissionCatalog, RoleSchema, UpdateRoleSchema } from '@tmlmobilidade/types';
3
+ import { CreateRoleSchema, PermissionCatalog, UpdateRoleSchema } from '@tmlmobilidade/types';
4
4
  import { AsyncSingletonProxy } from '@tmlmobilidade/utils';
5
5
  /* * */
6
6
  class RolesClass extends MongoCollectionClass {
7
7
  static _instance;
8
- createSchema = RoleSchema;
8
+ createSchema = CreateRoleSchema;
9
9
  updateSchema = UpdateRoleSchema;
10
10
  constructor() {
11
11
  super();
@@ -1,5 +1,5 @@
1
1
  import { MongoCollectionClass } from '../../common/mongo-collection.js';
2
- import { CreateSessionDto, Session, UpdateSessionDto } from '@tmlmobilidade/types';
2
+ import { type CreateSessionDto, Session, type UpdateSessionDto } from '@tmlmobilidade/types';
3
3
  import { IndexDescription } from 'mongodb';
4
4
  import { z } from 'zod';
5
5
  declare class SessionsClass extends MongoCollectionClass<Session, CreateSessionDto, UpdateSessionDto> {
@@ -1,12 +1,12 @@
1
1
  /* * */
2
2
  import { MongoCollectionClass } from '../../common/mongo-collection.js';
3
- import { SessionSchema } from '@tmlmobilidade/types';
3
+ import { CreateSessionSchema, UpdateSessionSchema } from '@tmlmobilidade/types';
4
4
  import { AsyncSingletonProxy } from '@tmlmobilidade/utils';
5
5
  /* * */
6
6
  class SessionsClass extends MongoCollectionClass {
7
7
  static _instance;
8
- createSchema = SessionSchema;
9
- updateSchema = SessionSchema;
8
+ createSchema = CreateSessionSchema;
9
+ updateSchema = UpdateSessionSchema;
10
10
  constructor() {
11
11
  super();
12
12
  }
@@ -32,4 +32,5 @@ class SessionsClass extends MongoCollectionClass {
32
32
  return 'DATABASE_URI';
33
33
  }
34
34
  }
35
+ /* * */
35
36
  export const sessions = AsyncSingletonProxy(SessionsClass);
@@ -101,4 +101,5 @@ class UsersClass extends MongoCollectionClass {
101
101
  };
102
102
  }
103
103
  }
104
+ /* * */
104
105
  export const users = AsyncSingletonProxy(UsersClass);
@@ -39,4 +39,5 @@ class VerificationTokensClass extends MongoCollectionClass {
39
39
  return 'DATABASE_URI';
40
40
  }
41
41
  }
42
+ /* * */
42
43
  export const verificationTokens = AsyncSingletonProxy(VerificationTokensClass);
@@ -1,11 +1,11 @@
1
1
  /* * */
2
2
  import { MongoCollectionClass } from '../../common/mongo-collection.js';
3
- import { AnnotationSchema, UpdateAnnotationSchema } from '@tmlmobilidade/types';
3
+ import { CreateAnnotationSchema, UpdateAnnotationSchema } from '@tmlmobilidade/types';
4
4
  import { AsyncSingletonProxy } from '@tmlmobilidade/utils';
5
5
  /* * */
6
6
  class AnnotationsClass extends MongoCollectionClass {
7
7
  static _instance;
8
- createSchema = AnnotationSchema;
8
+ createSchema = CreateAnnotationSchema;
9
9
  updateSchema = UpdateAnnotationSchema;
10
10
  constructor() {
11
11
  super();
@@ -1,5 +1,5 @@
1
1
  import { MongoCollectionClass } from '../../common/mongo-collection.js';
2
- import { CreateFileDto, File, UpdateFileDto } from '@tmlmobilidade/types';
2
+ import { type CreateFileDto, type File, type UpdateFileDto } from '@tmlmobilidade/types';
3
3
  import { DeleteOptions, DeleteResult, IndexDescription, InsertOneOptions, WithId } from 'mongodb';
4
4
  import { Readable } from 'node:stream';
5
5
  import { z } from 'zod';
@@ -4,12 +4,12 @@ import { StorageFactory } from '../../providers/index.js';
4
4
  import { HttpException, HttpStatus } from '@tmlmobilidade/consts';
5
5
  import { Files } from '@tmlmobilidade/files';
6
6
  import { generateRandomString } from '@tmlmobilidade/strings';
7
- import { CreateFileSchema, FileSchema, UpdateFileSchema } from '@tmlmobilidade/types';
7
+ import { CreateFileSchema, UpdateFileSchema } from '@tmlmobilidade/types';
8
8
  import { AsyncSingletonProxy, convertObject } from '@tmlmobilidade/utils';
9
9
  /* * */
10
10
  class FilesClass extends MongoCollectionClass {
11
11
  static _instance;
12
- createSchema = FileSchema;
12
+ createSchema = CreateFileSchema;
13
13
  updateSchema = UpdateFileSchema;
14
14
  bucketName;
15
15
  storageService;
@@ -1,5 +1,5 @@
1
1
  import { MongoCollectionClass } from '../../common/mongo-collection.js';
2
- import { CreateNotificationDto, Notification, UpdateNotificationDto, User } from '@tmlmobilidade/types';
2
+ import { type CreateNotificationDto, type Notification, UpdateNotificationDto, User } from '@tmlmobilidade/types';
3
3
  import { IndexDescription } from 'mongodb';
4
4
  import { z } from 'zod';
5
5
  declare class NotificationsClass extends MongoCollectionClass<Notification, CreateNotificationDto, UpdateNotificationDto> {
@@ -11,7 +11,6 @@ declare class NotificationsClass extends MongoCollectionClass<Notification, Crea
11
11
  sendNotification(scope: string, topic: string, user: User, id: string, title: string, description: string): Promise<void>;
12
12
  protected getCollectionIndexes(): IndexDescription[];
13
13
  protected getCollectionName(): string;
14
- protected getCreateSchema(): z.ZodSchema;
15
14
  protected getEnvName(): string;
16
15
  /**
17
16
  * Collects all effective permissions of a user (direct + via roles),
@@ -4,12 +4,12 @@ import { roles } from '../auth/roles.js';
4
4
  import { users } from '../auth/users.js';
5
5
  import { getAppConfig } from '@tmlmobilidade/consts';
6
6
  import { sendNotificationEmail } from '@tmlmobilidade/emails';
7
- import { NotificationSchema, UpdateNotificationSchema } from '@tmlmobilidade/types';
7
+ import { CreateNotificationSchema, UpdateNotificationSchema } from '@tmlmobilidade/types';
8
8
  import { AsyncSingletonProxy, mergeObjects } from '@tmlmobilidade/utils';
9
9
  /* * */
10
10
  class NotificationsClass extends MongoCollectionClass {
11
11
  static _instance;
12
- createSchema = NotificationSchema;
12
+ createSchema = CreateNotificationSchema;
13
13
  updateSchema = UpdateNotificationSchema;
14
14
  constructor() {
15
15
  super();
@@ -79,9 +79,6 @@ class NotificationsClass extends MongoCollectionClass {
79
79
  getCollectionName() {
80
80
  return 'notifications';
81
81
  }
82
- getCreateSchema() {
83
- return NotificationSchema;
84
- }
85
82
  getEnvName() {
86
83
  return 'DATABASE_URI';
87
84
  }
@@ -110,4 +107,5 @@ class NotificationsClass extends MongoCollectionClass {
110
107
  return permission['resource']?.send_mail ?? false;
111
108
  }
112
109
  }
110
+ /* * */
113
111
  export const notifications = AsyncSingletonProxy(NotificationsClass);
@@ -1,5 +1,5 @@
1
1
  import { MongoCollectionClass } from '../../common/mongo-collection.js';
2
- import { CreateOrganizationDto, Organization, UpdateOrganizationDto } from '@tmlmobilidade/types';
2
+ import { type CreateOrganizationDto, type Organization, type UpdateOrganizationDto } from '@tmlmobilidade/types';
3
3
  import { IndexDescription } from 'mongodb';
4
4
  import { z } from 'zod';
5
5
  declare class OrganizationsClass extends MongoCollectionClass<Organization, CreateOrganizationDto, UpdateOrganizationDto> {
@@ -10,7 +10,6 @@ declare class OrganizationsClass extends MongoCollectionClass<Organization, Crea
10
10
  static getInstance(): Promise<OrganizationsClass>;
11
11
  protected getCollectionIndexes(): IndexDescription[];
12
12
  protected getCollectionName(): string;
13
- protected getCreateSchema(): z.ZodSchema;
14
13
  protected getEnvName(): string;
15
14
  }
16
15
  export declare const organizations: OrganizationsClass;
@@ -1,11 +1,11 @@
1
1
  /* * */
2
2
  import { MongoCollectionClass } from '../../common/mongo-collection.js';
3
- import { OrganizationSchema, UpdateOrganizationSchema } from '@tmlmobilidade/types';
3
+ import { CreateOrganizationSchema, UpdateOrganizationSchema } from '@tmlmobilidade/types';
4
4
  import { AsyncSingletonProxy } from '@tmlmobilidade/utils';
5
5
  /* * */
6
6
  class OrganizationsClass extends MongoCollectionClass {
7
7
  static _instance;
8
- createSchema = OrganizationSchema;
8
+ createSchema = CreateOrganizationSchema;
9
9
  updateSchema = UpdateOrganizationSchema;
10
10
  constructor() {
11
11
  super();
@@ -26,9 +26,6 @@ class OrganizationsClass extends MongoCollectionClass {
26
26
  getCollectionName() {
27
27
  return 'organizations';
28
28
  }
29
- getCreateSchema() {
30
- return OrganizationSchema;
31
- }
32
29
  getEnvName() {
33
30
  return 'DATABASE_URI';
34
31
  }
@@ -1,11 +1,11 @@
1
1
  /* * */
2
2
  import { MongoCollectionClass } from '../../common/mongo-collection.js';
3
- import { PlanSchema, UpdatePlanSchema } from '@tmlmobilidade/types';
3
+ import { CreatePlanSchema, UpdatePlanSchema } from '@tmlmobilidade/types';
4
4
  import { AsyncSingletonProxy } from '@tmlmobilidade/utils';
5
5
  /* * */
6
6
  class PlansClass extends MongoCollectionClass {
7
7
  static _instance;
8
- createSchema = PlanSchema;
8
+ createSchema = CreatePlanSchema;
9
9
  updateSchema = UpdatePlanSchema;
10
10
  constructor() {
11
11
  super();
@@ -1,5 +1,5 @@
1
1
  import { MongoCollectionClass } from '../../common/mongo-collection.js';
2
- import { CreateRideAcceptanceDto, RideAcceptance, UpdateRideAcceptanceDto } from '@tmlmobilidade/types';
2
+ import { type CreateRideAcceptanceDto, type RideAcceptance, type UpdateRideAcceptanceDto } from '@tmlmobilidade/types';
3
3
  import { IndexDescription, InsertOneOptions, UpdateOptions } from 'mongodb';
4
4
  import { z } from 'zod';
5
5
  declare class RideAcceptanceClass extends MongoCollectionClass<RideAcceptance, CreateRideAcceptanceDto, UpdateRideAcceptanceDto> {
@@ -2,12 +2,12 @@
2
2
  import { MongoCollectionClass } from '../../common/mongo-collection.js';
3
3
  import { HttpException, HttpStatus } from '@tmlmobilidade/consts';
4
4
  import { Dates } from '@tmlmobilidade/dates';
5
- import { RideAcceptanceSchema, UpdateRideAcceptanceSchema } from '@tmlmobilidade/types';
5
+ import { CreateRideAcceptanceSchema, UpdateRideAcceptanceSchema } from '@tmlmobilidade/types';
6
6
  import { AsyncSingletonProxy, compareObjects, flattenObject } from '@tmlmobilidade/utils';
7
7
  /* * */
8
8
  class RideAcceptanceClass extends MongoCollectionClass {
9
9
  static _instance;
10
- createSchema = RideAcceptanceSchema;
10
+ createSchema = CreateRideAcceptanceSchema;
11
11
  updateSchema = UpdateRideAcceptanceSchema;
12
12
  constructor() {
13
13
  super();
@@ -1,5 +1,5 @@
1
1
  import { MongoCollectionClass } from '../../common/mongo-collection.js';
2
- import { CreateRideDto, Ride, UpdateRideDto } from '@tmlmobilidade/types';
2
+ import { type CreateRideDto, type Ride, type UpdateRideDto } from '@tmlmobilidade/types';
3
3
  import { IndexDescription } from 'mongodb';
4
4
  import { z } from 'zod';
5
5
  declare class RidesClass extends MongoCollectionClass<Ride, CreateRideDto, UpdateRideDto> {
@@ -1,11 +1,11 @@
1
1
  /* * */
2
2
  import { MongoCollectionClass } from '../../common/mongo-collection.js';
3
- import { RideSchema, UpdateRideSchema } from '@tmlmobilidade/types';
3
+ import { CreateRideSchema, UpdateRideSchema } from '@tmlmobilidade/types';
4
4
  import { AsyncSingletonProxy } from '@tmlmobilidade/utils';
5
5
  /* * */
6
6
  class RidesClass extends MongoCollectionClass {
7
7
  static _instance;
8
- createSchema = RideSchema;
8
+ createSchema = CreateRideSchema;
9
9
  updateSchema = UpdateRideSchema;
10
10
  constructor() {
11
11
  super();
@@ -1,11 +1,11 @@
1
1
  /* * */
2
2
  import { MongoCollectionClass } from '../../common/mongo-collection.js';
3
- import { SamSchema, UpdateSamSchema } from '@tmlmobilidade/types';
3
+ import { CreateSamSchema, UpdateSamSchema } from '@tmlmobilidade/types';
4
4
  import { AsyncSingletonProxy } from '@tmlmobilidade/utils';
5
5
  /* * */
6
6
  class SamsClass extends MongoCollectionClass {
7
7
  static _instance;
8
- createSchema = SamSchema;
8
+ createSchema = CreateSamSchema;
9
9
  updateSchema = UpdateSamSchema;
10
10
  constructor() {
11
11
  super();
@@ -1,11 +1,11 @@
1
1
  /* * */
2
2
  import { MongoCollectionClass } from '../../common/mongo-collection.js';
3
- import { StopSchema, UpdateStopSchema } from '@tmlmobilidade/types';
3
+ import { CreateStopSchema, UpdateStopSchema } from '@tmlmobilidade/types';
4
4
  import { AsyncSingletonProxy } from '@tmlmobilidade/utils';
5
5
  /* * */
6
6
  class StopsClass extends MongoCollectionClass {
7
7
  static _instance;
8
- createSchema = StopSchema;
8
+ createSchema = CreateStopSchema;
9
9
  updateSchema = UpdateStopSchema;
10
10
  constructor() {
11
11
  super();
@@ -1,5 +1,5 @@
1
1
  import { MongoCollectionClass } from '../../common/mongo-collection.js';
2
- import { CreateZoneDto, UpdateZoneDto, Zone } from '@tmlmobilidade/types';
2
+ import { type CreateZoneDto, type UpdateZoneDto, type Zone } from '@tmlmobilidade/types';
3
3
  import { IndexDescription } from 'mongodb';
4
4
  import { z } from 'zod';
5
5
  declare class ZonesClass extends MongoCollectionClass<Zone, CreateZoneDto, UpdateZoneDto> {
@@ -1,11 +1,11 @@
1
1
  /* * */
2
2
  import { MongoCollectionClass } from '../../common/mongo-collection.js';
3
- import { UpdateZoneSchema, ZoneSchema } from '@tmlmobilidade/types';
3
+ import { CreateZoneSchema, UpdateZoneSchema } from '@tmlmobilidade/types';
4
4
  import { AsyncSingletonProxy } from '@tmlmobilidade/utils';
5
5
  /* * */
6
6
  class ZonesClass extends MongoCollectionClass {
7
7
  static _instance;
8
- createSchema = ZoneSchema;
8
+ createSchema = CreateZoneSchema;
9
9
  updateSchema = UpdateZoneSchema;
10
10
  constructor() {
11
11
  super();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmlmobilidade/interfaces",
3
- "version": "20251222.1552.52",
3
+ "version": "20251222.1756.6",
4
4
  "author": {
5
5
  "email": "iso@tmlmobilidade.pt",
6
6
  "name": "TML-ISO"