Update mongodb
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import * as mongo from 'mongodb';
|
||||
import { Context } from 'cafy';
|
||||
import isObjectId from './is-objectid';
|
||||
|
||||
export const isAnId = (x: any) => mongo.ObjectID.isValid(x);
|
||||
export const isNotAnId = (x: any) => !isAnId(x);
|
||||
@ -12,7 +13,7 @@ export default class ID extends Context<mongo.ObjectID> {
|
||||
super();
|
||||
|
||||
this.transform = v => {
|
||||
if (isAnId(v) && !mongo.ObjectID.prototype.isPrototypeOf(v)) {
|
||||
if (isAnId(v) && !isObjectId(v)) {
|
||||
return new mongo.ObjectID(v);
|
||||
} else {
|
||||
return v;
|
||||
@ -20,7 +21,7 @@ export default class ID extends Context<mongo.ObjectID> {
|
||||
};
|
||||
|
||||
this.push(v => {
|
||||
if (!mongo.ObjectID.prototype.isPrototypeOf(v) && isNotAnId(v)) {
|
||||
if (!isObjectId(v) && isNotAnId(v)) {
|
||||
return new Error('must-be-an-id');
|
||||
}
|
||||
return true;
|
||||
|
3
src/misc/is-objectid.ts
Normal file
3
src/misc/is-objectid.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export default function(x: any): boolean {
|
||||
return x.hasOwnProperty('toHexString') || x.hasOwnProperty('_bsontype');
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
import * as mongo from 'mongodb';
|
||||
import isObjectId from './is-objectid';
|
||||
|
||||
function toString(id: any) {
|
||||
return mongo.ObjectID.prototype.isPrototypeOf(id) ? (id as mongo.ObjectID).toHexString() : id;
|
||||
return isObjectId(id) ? (id as mongo.ObjectID).toHexString() : id;
|
||||
}
|
||||
|
||||
export default function(note: any, mutedUserIds: string[]): boolean {
|
||||
|
Reference in New Issue
Block a user