Fixed 267U.pre2

This commit is contained in:
2026-07-26 18:25:37 +09:00
parent 50bfaeafdf
commit 317d00a284
1286 changed files with 80222 additions and 1 deletions
@@ -0,0 +1,57 @@
import { db } from "../../db/postgre.js";
import { genId } from "../../misc/gen-id.js";
import { ShogiGame } from "../entities/shogi-game.js";
import { Users } from "../index.js";
function createdAtFromId(id) {
const time = parseInt(id.slice(0, 8), 36);
if (Number.isNaN(time)) return new Date().toISOString();
return new Date(time + 946684800000).toISOString();
}
export const ShogiGameRepository = db.getRepository(ShogiGame).extend({
async packDetail (src) {
const game = typeof src === "object" ? src : await this.findOneOrFail({
where: {
id: src
},
relations: {
user1: true,
user2: true
}
});
const user1 = await Users.pack(game.user1 ?? game.user1Id, null, {
detail: false
});
const user2 = await Users.pack(game.user2 ?? game.user2Id, null, {
detail: false
});
return {
id: game.id,
createdAt: createdAtFromId(game.id),
startedAt: game.startedAt?.toISOString() ?? null,
endedAt: game.endedAt?.toISOString() ?? null,
isStarted: game.isStarted,
isEnded: game.isEnded,
user1Ready: game.user1Ready,
user2Ready: game.user2Ready,
user1Id: game.user1Id,
user2Id: game.user2Id,
user1,
user2,
winnerId: game.winnerId,
winner: game.winnerId ? [
user1,
user2
].find((u)=>u.id === game.winnerId) ?? null : null,
surrenderedUserId: game.surrenderedUserId,
sente: game.sente,
sfen: game.sfen,
logs: game.logs
};
},
async packLite (src) {
const detail = await this.packDetail(src);
const { logs, ...lite } = detail;
return lite;
},
genId
});