管理画面からリモートユーザー情報を更新できるように (#3992)

This commit is contained in:
MeiMei 2019-01-26 17:53:35 +09:00 committed by syuilo
parent a0f8c7e94e
commit 0854f2e180
4 changed files with 94 additions and 2 deletions

View file

@ -1,5 +1,6 @@
import * as mongo from 'mongodb';
import Note from "../../../models/note";
import User, { isRemoteUser, isLocalUser } from "../../../models/user";
/**
* Get valied note for API processing
@ -16,3 +17,44 @@ export async function getValiedNote(noteId: mongo.ObjectID) {
return note;
}
/**
* Get user for API processing
*/
export async function getUser(userId: mongo.ObjectID) {
const user = await User.findOne({
_id: userId
});
if (user == null) {
throw 'user not found';
}
return user;
}
/**
* Get remote user for API processing
*/
export async function getRemoteUser(userId: mongo.ObjectID) {
const user = await getUser(userId);
if (!isRemoteUser(user)) {
throw 'user is not a remote user';
}
return user;
}
/**
* Get local user for API processing
*/
export async function getLocalUser(userId: mongo.ObjectID) {
const user = await getUser(userId);
if (!isLocalUser(user)) {
throw 'user is not a local user';
}
return user;
}