@tmlmobilidade/interfaces 20260828.1831.23 → 20260829.51.31
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type AggregationPipeline } from './aggregation-pipeline.js';
|
|
2
|
-
import { type
|
|
2
|
+
import { type UnixMilliseconds } from '@tmlmobilidade/go-types-shared';
|
|
3
3
|
import { MongoConnector } from '@tmlmobilidade/mongo';
|
|
4
4
|
import { type AggregateOptions, type AggregationCursor, type Collection, type DeleteOptions, type DeleteResult, type Document, type Filter, type FindOptions, Flatten, type IndexDescription, type InsertManyResult, type InsertOneOptions, type InsertOneResult, type MongoClientOptions, type UpdateOptions, type UpdateResult, type WithId } from 'mongodb';
|
|
5
5
|
import { z } from 'zod';
|
|
@@ -121,9 +121,9 @@ export declare abstract class MongoCollectionClass<T extends Document, TCreate,
|
|
|
121
121
|
*/
|
|
122
122
|
insertMany(docs: (TCreate & {
|
|
123
123
|
_id?: T['_id'];
|
|
124
|
-
created_at?:
|
|
124
|
+
created_at?: UnixMilliseconds;
|
|
125
125
|
created_by?: string;
|
|
126
|
-
updated_at?:
|
|
126
|
+
updated_at?: UnixMilliseconds;
|
|
127
127
|
updated_by?: string;
|
|
128
128
|
})[], { options, unsafe }?: {
|
|
129
129
|
options?: InsertOneOptions;
|
|
@@ -137,9 +137,9 @@ export declare abstract class MongoCollectionClass<T extends Document, TCreate,
|
|
|
137
137
|
*/
|
|
138
138
|
insertOne<TReturnDocument extends boolean = true>(doc: TCreate & {
|
|
139
139
|
_id?: T['_id'];
|
|
140
|
-
created_at?:
|
|
140
|
+
created_at?: UnixMilliseconds;
|
|
141
141
|
created_by?: string;
|
|
142
|
-
updated_at?:
|
|
142
|
+
updated_at?: UnixMilliseconds;
|
|
143
143
|
updated_by?: string;
|
|
144
144
|
}, { options, unsafe }?: {
|
|
145
145
|
options?: InsertOneOptions & {
|
|
@@ -185,7 +185,7 @@ export declare abstract class MongoCollectionClass<T extends Document, TCreate,
|
|
|
185
185
|
* @returns A promise that resolves to the result of the update operation
|
|
186
186
|
*/
|
|
187
187
|
updateMany<TReturnDocument extends boolean = true>(filter: Filter<T>, updateFields: TUpdate & {
|
|
188
|
-
updated_at?:
|
|
188
|
+
updated_at?: UnixMilliseconds;
|
|
189
189
|
updated_by?: string;
|
|
190
190
|
}, options?: UpdateOptions & {
|
|
191
191
|
returnResults?: TReturnDocument;
|
|
@@ -187,9 +187,9 @@ export class MongoCollectionClass {
|
|
|
187
187
|
return {
|
|
188
188
|
...doc,
|
|
189
189
|
_id: doc._id || generateRandomString({ length: 5 }),
|
|
190
|
-
created_at: doc.created_at || Dates.now('utc').
|
|
190
|
+
created_at: doc.created_at || Dates.now('utc').unix_milliseconds,
|
|
191
191
|
created_by: doc.created_by || 'system',
|
|
192
|
-
updated_at: doc.updated_at || Dates.now('utc').
|
|
192
|
+
updated_at: doc.updated_at || Dates.now('utc').unix_milliseconds,
|
|
193
193
|
updated_by: doc.updated_by || 'system',
|
|
194
194
|
};
|
|
195
195
|
});
|
|
@@ -255,11 +255,11 @@ export class MongoCollectionClass {
|
|
|
255
255
|
}
|
|
256
256
|
// Add default fields if they are missing from the original document
|
|
257
257
|
if (!doc.created_at)
|
|
258
|
-
parsedDocument.created_at = Dates.now('utc').
|
|
258
|
+
parsedDocument.created_at = Dates.now('utc').unix_milliseconds;
|
|
259
259
|
if (!doc.created_by)
|
|
260
260
|
parsedDocument.created_by = 'system';
|
|
261
261
|
if (!doc.updated_at)
|
|
262
|
-
parsedDocument.updated_at = Dates.now('utc').
|
|
262
|
+
parsedDocument.updated_at = Dates.now('utc').unix_milliseconds;
|
|
263
263
|
if (!doc.updated_by)
|
|
264
264
|
parsedDocument.updated_by = 'system';
|
|
265
265
|
// Add the ID if it is missing from the original document
|
|
@@ -358,7 +358,7 @@ export class MongoCollectionClass {
|
|
|
358
358
|
async updateMany(filter, updateFields, options) {
|
|
359
359
|
let parsedUpdateFields = {
|
|
360
360
|
...updateFields,
|
|
361
|
-
updated_at: updateFields.updated_at || Dates.now('utc').
|
|
361
|
+
updated_at: updateFields.updated_at || Dates.now('utc').unix_milliseconds,
|
|
362
362
|
updated_by: updateFields.updated_by || 'system',
|
|
363
363
|
};
|
|
364
364
|
if (this.updateSchema) {
|
|
@@ -369,7 +369,7 @@ export class MongoCollectionClass {
|
|
|
369
369
|
throw new HttpException(HTTP_STATUS.BAD_REQUEST, error.message, { cause: error });
|
|
370
370
|
}
|
|
371
371
|
}
|
|
372
|
-
const result = await this.mongoCollection.updateMany(filter, { $set: { ...parsedUpdateFields, updated_at: Dates.now('utc').
|
|
372
|
+
const result = await this.mongoCollection.updateMany(filter, { $set: { ...parsedUpdateFields, updated_at: Dates.now('utc').unix_milliseconds } }, options);
|
|
373
373
|
if (options?.returnResults === false)
|
|
374
374
|
return result;
|
|
375
375
|
if (!result.acknowledged) {
|
|
@@ -406,7 +406,7 @@ export class MongoCollectionClass {
|
|
|
406
406
|
throw new HttpException(HTTP_STATUS.BAD_REQUEST, error.message, { cause: error });
|
|
407
407
|
}
|
|
408
408
|
}
|
|
409
|
-
const result = await this.mongoCollection.updateOne(filter, { $set: { ...parsedUpdateFields, updated_at: Dates.now('utc').
|
|
409
|
+
const result = await this.mongoCollection.updateOne(filter, { $set: { ...parsedUpdateFields, updated_at: Dates.now('utc').unix_milliseconds } }, options);
|
|
410
410
|
if (options?.returnResult === false)
|
|
411
411
|
return result;
|
|
412
412
|
if (!result.acknowledged) {
|