universo-platform-3d
64 строки · 1.7 Кб
1import { PipelineStage } from 'mongoose'2export type MongoObjectIdString = string3
4// The intent for these is to increase static typing usage for more safety, e.g. to ensure a spaceId isn't inputted where a userId should be.
5export type SpaceId = string6export type SpaceObjectId = string7export type SpaceVersionId = string8export type MaterialInstanceId = string9export type AssetId = string10export type UserId = string11export type UserGroupId = string12export type UserEntityActionId = string13export type TagId = string14export type UserFeedbackItemId = string15export type ZoneId = string16export type MirrorDBRecordId = string17export type PurchaseOptionId = string18/**
19* @description SCALER UUID
20*/
21export type ScalerContainerUuid = string22/**
23* @description alias for ZoneId, but to be clear that it's a Mongo ObjectId and NOT a UUID
24*/
25export type MongoZoneId = string26export type CustomDataId = string27export type SpaceVariablesDataId = string28export type BlockId = string29
30export type EntityId =31| SpaceId32| SpaceObjectId33| AssetId34| UserId35| TagId36| UserFeedbackItemId37| UserGroupId38| ZoneId39| CustomDataId40| BlockId41
42/**
43* @description After hours of debugging, this is how you have to $match query for an id that could be either an ObjectId or a String. We need to standardize this at some point. Mongoose automatically casts strings<>ObjectIds, but an aggregation pipeline does not.
44* @date 2023-05-04 00:36
45*/
46export function aggregationMatchId(47idToMatch: string,48key = '$_id'49): PipelineStage {50return {51$match: {52$expr: {53$or: [54{55$eq: [key, { $toObjectId: idToMatch }]56},57{58$eq: [key, idToMatch]59}60]61}62}63}64}
65