Fixed some bugs on FaTimestamps

This commit is contained in:
SepehrYahyaee
2026-04-20 12:11:12 +03:30
parent b826a133a4
commit 95bfc095ce
2 changed files with 14 additions and 6 deletions

View File

@@ -46,15 +46,24 @@ function writeFaTimestampsOnUpdate(query: Query<any, any>): void {
update.$set = {};
}
if (update.$set.createdAtFa == null && update.createdAtFa == null) {
update.$set.createdAtFa = nowFa;
}
update.$set.updatedAtFa = nowFa;
// Keep createdAtFa immutable on regular updates; set only for upsert inserts.
const opts = (query as any).getOptions?.() ?? {};
if (opts.upsert) {
if (!update.$setOnInsert || typeof update.$setOnInsert !== "object") {
update.$setOnInsert = {};
}
if (update.$setOnInsert.createdAtFa == null) {
update.$setOnInsert.createdAtFa = nowFa;
}
}
query.setUpdate(update);
}
/**
* Adds `createdAtFa` / `updatedAtFa` (Iran timezone, UTC+03:30 offset string)
* Adds `createdAtFa` / `updatedAtFa` (Iran timezone tuple: [date, time])
* to all schemas that use mongoose timestamps.
*/
export function applyIranFaTimestampPlugin(connection: Connection): void {