@tmlmobilidade/interfaces 20250915.1116.6 → 20250915.1306.2

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.
@@ -49,7 +49,7 @@ declare class UsersClass extends MongoCollectionClass<User, CreateUserDto, Updat
49
49
  email_verified?: import("@tmlmobilidade/types").UnixTimestamp | null | undefined;
50
50
  first_name: string;
51
51
  last_name: string;
52
- organization_ids: string[];
52
+ organization_id?: string | null | undefined | undefined;
53
53
  preferences?: Record<string, Record<string, string | number | boolean | string[] | number[]>> | null | undefined;
54
54
  role_ids: string[];
55
55
  session_ids: string[];
@@ -80,7 +80,7 @@ declare class UsersClass extends MongoCollectionClass<User, CreateUserDto, Updat
80
80
  email_verified?: import("@tmlmobilidade/types").UnixTimestamp | null | undefined;
81
81
  first_name: string;
82
82
  last_name: string;
83
- organization_ids: string[];
83
+ organization_id?: string | null | undefined | undefined;
84
84
  preferences?: Record<string, Record<string, string | number | boolean | string[] | number[]>> | null | undefined;
85
85
  role_ids: string[];
86
86
  session_ids: string[];
@@ -53,7 +53,7 @@ class UsersClass extends MongoCollectionClass {
53
53
  * @returns A promise that resolves to the matching user documents or null if not found
54
54
  */
55
55
  async findByOrganization(id, includePasswordHash = false) {
56
- const users = await this.mongoCollection.find({ organization_ids: { $in: [id] } }).toArray();
56
+ const users = await this.mongoCollection.find({ organization_id: { $in: [id] } }).toArray();
57
57
  return includePasswordHash ? users : users.map(user => this.deletePasswordHash(user));
58
58
  }
59
59
  /**
@@ -1,6 +1,6 @@
1
1
  import { MongoCollectionClass } from '../../mongo-collection.js';
2
2
  import { CreateOrganizationDto, Organization, UpdateOrganizationDto } from '@tmlmobilidade/types';
3
- import { IndexDescription } from 'mongodb';
3
+ import { Filter, FindOptions, IndexDescription } from 'mongodb';
4
4
  import { z } from 'zod';
5
5
  declare class OrganizationsClass extends MongoCollectionClass<Organization, CreateOrganizationDto, UpdateOrganizationDto> {
6
6
  private static _instance;
@@ -9,12 +9,12 @@ declare class OrganizationsClass extends MongoCollectionClass<Organization, Crea
9
9
  private constructor();
10
10
  static getInstance(): Promise<OrganizationsClass>;
11
11
  /**
12
- * Finds an organization by its code
12
+ * Finds a document by its ID.
13
13
  *
14
- * @param code - The code of the organization to find
15
- * @returns A promise that resolves to the matching organization document or null if not found
14
+ * @param id - The ID of the document to find
15
+ * @returns A promise that resolves to the matching document or null if not found
16
16
  */
17
- findByCode(code: string): Promise<import("mongodb").WithId<{
17
+ findById(id: string, options?: FindOptions<Organization>): Promise<{
18
18
  _id: string;
19
19
  created_at: number & {
20
20
  __brand: "UnixTimestamp";
@@ -22,19 +22,16 @@ declare class OrganizationsClass extends MongoCollectionClass<Organization, Crea
22
22
  updated_at: number & {
23
23
  __brand: "UnixTimestamp";
24
24
  };
25
- code: string;
26
- name: string;
25
+ home_links: string[];
26
+ home_wikis: string[];
27
+ longname: string;
28
+ shortname: string;
27
29
  created_by?: string | undefined;
28
30
  updated_by?: string | undefined;
29
- }> | null>;
30
- /**
31
- * Updates an organization by its code
32
- *
33
- * @param code - The code of the organization to update
34
- * @param fields - The fields to update
35
- * @returns A promise that resolves to the result of the update operation
36
- */
37
- updateByCode(code: string, fields: Partial<Organization>): Promise<import("mongodb").UpdateResult<{
31
+ logo?: string | null | undefined;
32
+ theme?: string | null | undefined;
33
+ } | null>;
34
+ findOne(filter: Filter<Organization>): Promise<import("mongodb").WithId<{
38
35
  _id: string;
39
36
  created_at: number & {
40
37
  __brand: "UnixTimestamp";
@@ -42,13 +39,18 @@ declare class OrganizationsClass extends MongoCollectionClass<Organization, Crea
42
39
  updated_at: number & {
43
40
  __brand: "UnixTimestamp";
44
41
  };
45
- code: string;
46
- name: string;
42
+ home_links: string[];
43
+ home_wikis: string[];
44
+ longname: string;
45
+ shortname: string;
47
46
  created_by?: string | undefined;
48
47
  updated_by?: string | undefined;
49
- }>>;
48
+ logo?: string | null | undefined;
49
+ theme?: string | null | undefined;
50
+ }> | null>;
50
51
  protected getCollectionIndexes(): IndexDescription[];
51
52
  protected getCollectionName(): string;
53
+ protected getCreateSchema(): z.ZodSchema;
52
54
  protected getEnvName(): string;
53
55
  }
54
56
  export declare const organizations: OrganizationsClass;
@@ -1,11 +1,11 @@
1
1
  /* * */
2
2
  import { MongoCollectionClass } from '../../mongo-collection.js';
3
- import { OrganizationSchema, UpdateOrganizationSchema } from '@tmlmobilidade/types';
3
+ import { CreateOrganizationSchema, OrganizationSchema, 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();
@@ -19,23 +19,24 @@ class OrganizationsClass extends MongoCollectionClass {
19
19
  return OrganizationsClass._instance;
20
20
  }
21
21
  /**
22
- * Finds an organization by its code
22
+ * Finds a document by its ID.
23
23
  *
24
- * @param code - The code of the organization to find
25
- * @returns A promise that resolves to the matching organization document or null if not found
24
+ * @param id - The ID of the document to find
25
+ * @returns A promise that resolves to the matching document or null if not found
26
26
  */
27
- async findByCode(code) {
28
- return this.mongoCollection.findOne({ code });
27
+ async findById(id, options) {
28
+ const organization = await this.mongoCollection.findOne({ _id: id }, options);
29
+ if (!organization) {
30
+ return null;
31
+ }
32
+ return organization;
29
33
  }
30
- /**
31
- * Updates an organization by its code
32
- *
33
- * @param code - The code of the organization to update
34
- * @param fields - The fields to update
35
- * @returns A promise that resolves to the result of the update operation
36
- */
37
- async updateByCode(code, fields) {
38
- return this.mongoCollection.updateOne({ code }, { $set: fields });
34
+ async findOne(filter) {
35
+ const organization = await this.mongoCollection.findOne(filter);
36
+ if (!organization) {
37
+ return null;
38
+ }
39
+ return organization;
39
40
  }
40
41
  getCollectionIndexes() {
41
42
  return [
@@ -45,8 +46,11 @@ class OrganizationsClass extends MongoCollectionClass {
45
46
  getCollectionName() {
46
47
  return 'organizations';
47
48
  }
49
+ getCreateSchema() {
50
+ return OrganizationSchema;
51
+ }
48
52
  getEnvName() {
49
- return 'TML_INTERFACE_ORGANIZATIONS';
53
+ return 'DATABASE_URI';
50
54
  }
51
55
  }
52
56
  export const organizations = AsyncSingletonProxy(OrganizationsClass);
@@ -8,6 +8,9 @@ declare class RideJustificationClass extends MongoCollectionClass<RideJustificat
8
8
  protected updateSchema: z.ZodSchema;
9
9
  private constructor();
10
10
  static getInstance(): Promise<RideJustificationClass>;
11
+ createByTripId(trip_id: string, data: CreateRideJustificationDto): Promise<RideJustification>;
12
+ findByTripId(trip_id: string): Promise<null | RideJustification>;
13
+ updateByTripId(trip_id: string, data: UpdateRideJustificationDto): Promise<RideJustification>;
11
14
  protected getCollectionIndexes(): IndexDescription[];
12
15
  protected getCollectionName(): string;
13
16
  protected getEnvName(): string;
@@ -18,6 +18,15 @@ class RideJustificationClass extends MongoCollectionClass {
18
18
  }
19
19
  return RideJustificationClass._instance;
20
20
  }
21
+ async createByTripId(trip_id, data) {
22
+ return super.insertOne({ ...data, trip_id });
23
+ }
24
+ async findByTripId(trip_id) {
25
+ return super.findOne({ trip_id });
26
+ }
27
+ async updateByTripId(trip_id, data) {
28
+ return super.updateOne({ trip_id }, data);
29
+ }
21
30
  getCollectionIndexes() {
22
31
  return [
23
32
  { background: true, key: { trip_id: 1 } },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmlmobilidade/interfaces",
3
- "version": "20250915.1116.6",
3
+ "version": "20250915.1306.2",
4
4
  "author": "João de Vasconcelos & Jusi Monteiro",
5
5
  "license": "AGPL-3.0-or-later",
6
6
  "homepage": "https://github.com/tmlmobilidade/services#readme",