|
|
@@ -3,21 +3,9 @@ import mongoose from 'mongoose';
|
|
|
type IObjectId = mongoose.Types.ObjectId;
|
|
|
const ObjectId = mongoose.Types.ObjectId;
|
|
|
|
|
|
-const castToString = (val: string | IObjectId) => {
|
|
|
- if (typeof val === 'string') {
|
|
|
- return val;
|
|
|
- }
|
|
|
-
|
|
|
- return val.toString();
|
|
|
-};
|
|
|
-
|
|
|
-export const compareObjectId = (id1: IObjectId | string, id2: IObjectId | string): boolean => {
|
|
|
- return castToString(id1) === castToString(id2);
|
|
|
-};
|
|
|
-
|
|
|
export const isIncludesObjectId = (arr: (IObjectId | string)[], id: IObjectId | string): boolean => {
|
|
|
- const _arr = arr.map(i => castToString(i));
|
|
|
- const _id = castToString(id);
|
|
|
+ const _arr = arr.map(i => i.toString());
|
|
|
+ const _id = id.toString();
|
|
|
|
|
|
return _arr.includes(_id);
|
|
|
};
|
|
|
@@ -30,8 +18,8 @@ export const isIncludesObjectId = (arr: (IObjectId | string)[], id: IObjectId |
|
|
|
*/
|
|
|
export const excludeTestIdsFromTargetIds = (targetIds: (IObjectId | string)[], testIds: (IObjectId | string)[]): IObjectId[] => {
|
|
|
// cast to string
|
|
|
- const arr1 = targetIds.map(e => castToString(e));
|
|
|
- const arr2 = testIds.map(e => castToString(e));
|
|
|
+ const arr1 = targetIds.map(e => e.toString());
|
|
|
+ const arr2 = testIds.map(e => e.toString());
|
|
|
|
|
|
// filter
|
|
|
const excluded = arr1.filter(e => !arr2.includes(e));
|
|
|
@@ -42,7 +30,7 @@ export const excludeTestIdsFromTargetIds = (targetIds: (IObjectId | string)[], t
|
|
|
|
|
|
export const removeDuplicates = (objectIds: (IObjectId | string)[]): IObjectId[] => {
|
|
|
// cast to string
|
|
|
- const strs = objectIds.map(id => castToString(id));
|
|
|
+ const strs = objectIds.map(id => id.toString());
|
|
|
const uniqueArr = Array.from(new Set(strs));
|
|
|
|
|
|
// cast to ObjectId
|