Update mongodb

This commit is contained in:
syuilo
2018-10-16 11:38:09 +09:00
parent d32b2a8ce5
commit 9427a756c9
31 changed files with 83 additions and 52 deletions

View File

@@ -2,6 +2,7 @@ import * as mongo from 'mongodb';
const deepcopy = require('deepcopy');
import rap from '@prezzemolo/rap';
import db from '../db/mongodb';
import isObjectId from '../misc/is-objectid';
import { length } from 'stringz';
import { IUser, pack as packUser } from './user';
import { pack as packApp } from './app';
@@ -107,7 +108,7 @@ export async function deleteNote(note: string | mongo.ObjectID | INote) {
let n: INote;
// Populate
if (mongo.ObjectID.prototype.isPrototypeOf(note)) {
if (isObjectId(note)) {
n = await Note.findOne({
_id: note
});
@@ -259,7 +260,7 @@ export const pack = async (
// Me
const meId: mongo.ObjectID = me
? mongo.ObjectID.prototype.isPrototypeOf(me)
? isObjectId(me)
? me as mongo.ObjectID
: typeof me === 'string'
? new mongo.ObjectID(me)
@@ -269,7 +270,7 @@ export const pack = async (
let _note: any;
// Populate the note if 'note' is ID
if (mongo.ObjectID.prototype.isPrototypeOf(note)) {
if (isObjectId(note)) {
_note = await Note.findOne({
_id: note
});