Files
2026-07-26 18:25:37 +09:00

55 lines
1.6 KiB
JavaScript

import define from "../../define.js";
import { ApiError } from "../../error.js";
import { ShogiGames, Users } from "../../../../models/index.js";
import { matchAnyUser, matchSpecificUser } from "../../../../services/shogi/index.js";
export const meta = {
tags: [
"shogi"
],
requireCredential: true,
kind: "write:account",
errors: {
noSuchUser: {
message: "No such user.",
code: "NO_SUCH_USER",
id: "6dc7bf6e-d472-42ec-95c7-43d8f91ecf97"
},
isYourself: {
message: "Target user is yourself.",
code: "TARGET_IS_YOURSELF",
id: "d7cb9670-245e-4fc4-90d0-11cc1796f647"
}
},
res: {
type: "object",
optional: true,
nullable: false
}
};
export const paramDef = {
type: "object",
properties: {
userId: {
type: "string",
format: "misskey:id",
nullable: true
},
multiple: {
type: "boolean",
default: false
}
},
required: []
};
export default define(meta, paramDef, async (ps, user)=>{
if (ps.userId === user.id) throw new ApiError(meta.errors.isYourself);
const target = ps.userId ? await Users.findOneBy({
id: ps.userId
}).then((u)=>{
if (!u) throw new ApiError(meta.errors.noSuchUser);
return u;
}) : null;
const game = target ? await matchSpecificUser(user, target, ps.multiple) : await matchAnyUser(user, ps.multiple);
return game ? await ShogiGames.packDetail(game) : undefined;
});