summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/othello
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/api/endpoints/othello')
-rw-r--r--src/server/api/endpoints/othello/games.ts28
-rw-r--r--src/server/api/endpoints/othello/games/show.ts16
-rw-r--r--src/server/api/endpoints/othello/invitations.ts2
-rw-r--r--src/server/api/endpoints/othello/match.ts44
-rw-r--r--src/server/api/endpoints/othello/match/cancel.ts2
5 files changed, 46 insertions, 46 deletions
diff --git a/src/server/api/endpoints/othello/games.ts b/src/server/api/endpoints/othello/games.ts
index 2a6bbb4043..37fa384189 100644
--- a/src/server/api/endpoints/othello/games.ts
+++ b/src/server/api/endpoints/othello/games.ts
@@ -1,5 +1,5 @@
import $ from 'cafy';
-import Game, { pack } from '../../models/othello-game';
+import OthelloGame, { pack } from '../../models/othello-game';
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'my' parameter
@@ -10,28 +10,28 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
if (limitErr) return rej('invalid limit param');
- // Get 'since_id' parameter
- const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
- if (sinceIdErr) return rej('invalid since_id param');
+ // Get 'sinceId' parameter
+ const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
+ if (sinceIdErr) return rej('invalid sinceId param');
- // Get 'until_id' parameter
- const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
- if (untilIdErr) return rej('invalid until_id param');
+ // Get 'untilId' parameter
+ const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
+ if (untilIdErr) return rej('invalid untilId param');
- // Check if both of since_id and until_id is specified
+ // Check if both of sinceId and untilId is specified
if (sinceId && untilId) {
- return rej('cannot set since_id and until_id');
+ return rej('cannot set sinceId and untilId');
}
const q: any = my ? {
- is_started: true,
+ isStarted: true,
$or: [{
- user1_id: user._id
+ user1Id: user._id
}, {
- user2_id: user._id
+ user2Id: user._id
}]
} : {
- is_started: true
+ isStarted: true
};
const sort = {
@@ -50,7 +50,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
}
// Fetch games
- const games = await Game.find(q, {
+ const games = await OthelloGame.find(q, {
sort,
limit
});
diff --git a/src/server/api/endpoints/othello/games/show.ts b/src/server/api/endpoints/othello/games/show.ts
index 2b0db4dd00..f9084682fa 100644
--- a/src/server/api/endpoints/othello/games/show.ts
+++ b/src/server/api/endpoints/othello/games/show.ts
@@ -1,22 +1,22 @@
import $ from 'cafy';
-import Game, { pack } from '../../../models/othello-game';
+import OthelloGame, { pack } from '../../../models/othello-game';
import Othello from '../../../../common/othello/core';
module.exports = (params, user) => new Promise(async (res, rej) => {
- // Get 'game_id' parameter
- const [gameId, gameIdErr] = $(params.game_id).id().$;
- if (gameIdErr) return rej('invalid game_id param');
+ // Get 'gameId' parameter
+ const [gameId, gameIdErr] = $(params.gameId).id().$;
+ if (gameIdErr) return rej('invalid gameId param');
- const game = await Game.findOne({ _id: gameId });
+ const game = await OthelloGame.findOne({ _id: gameId });
if (game == null) {
return rej('game not found');
}
const o = new Othello(game.settings.map, {
- isLlotheo: game.settings.is_llotheo,
- canPutEverywhere: game.settings.can_put_everywhere,
- loopedBoard: game.settings.looped_board
+ isLlotheo: game.settings.isLlotheo,
+ canPutEverywhere: game.settings.canPutEverywhere,
+ loopedBoard: game.settings.loopedBoard
});
game.logs.forEach(log => {
diff --git a/src/server/api/endpoints/othello/invitations.ts b/src/server/api/endpoints/othello/invitations.ts
index 02fb421fbc..f6e0071a6c 100644
--- a/src/server/api/endpoints/othello/invitations.ts
+++ b/src/server/api/endpoints/othello/invitations.ts
@@ -3,7 +3,7 @@ import Matching, { pack as packMatching } from '../../models/othello-matching';
module.exports = (params, user) => new Promise(async (res, rej) => {
// Find session
const invitations = await Matching.find({
- child_id: user._id
+ childId: user._id
}, {
sort: {
_id: -1
diff --git a/src/server/api/endpoints/othello/match.ts b/src/server/api/endpoints/othello/match.ts
index b73e105ef0..f503c5834c 100644
--- a/src/server/api/endpoints/othello/match.ts
+++ b/src/server/api/endpoints/othello/match.ts
@@ -1,24 +1,24 @@
import $ from 'cafy';
import Matching, { pack as packMatching } from '../../models/othello-matching';
-import Game, { pack as packGame } from '../../models/othello-game';
+import OthelloGame, { pack as packGame } from '../../models/othello-game';
import User from '../../models/user';
import publishUserStream, { publishOthelloStream } from '../../event';
import { eighteight } from '../../../common/othello/maps';
module.exports = (params, user) => new Promise(async (res, rej) => {
- // Get 'user_id' parameter
- const [childId, childIdErr] = $(params.user_id).id().$;
- if (childIdErr) return rej('invalid user_id param');
+ // Get 'userId' parameter
+ const [childId, childIdErr] = $(params.userId).id().$;
+ if (childIdErr) return rej('invalid userId param');
// Myself
if (childId.equals(user._id)) {
- return rej('invalid user_id param');
+ return rej('invalid userId param');
}
// Find session
const exist = await Matching.findOne({
- parent_id: childId,
- child_id: user._id
+ parentId: childId,
+ childId: user._id
});
if (exist) {
@@ -28,29 +28,29 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
});
// Create game
- const game = await Game.insert({
- created_at: new Date(),
- user1_id: exist.parent_id,
- user2_id: user._id,
- user1_accepted: false,
- user2_accepted: false,
- is_started: false,
- is_ended: false,
+ const game = await OthelloGame.insert({
+ createdAt: new Date(),
+ user1Id: exist.parentId,
+ user2Id: user._id,
+ user1Accepted: false,
+ user2Accepted: false,
+ isStarted: false,
+ isEnded: false,
logs: [],
settings: {
map: eighteight.data,
bw: 'random',
- is_llotheo: false
+ isLlotheo: false
}
});
// Reponse
res(await packGame(game, user));
- publishOthelloStream(exist.parent_id, 'matched', await packGame(game, exist.parent_id));
+ publishOthelloStream(exist.parentId, 'matched', await packGame(game, exist.parentId));
const other = await Matching.count({
- child_id: user._id
+ childId: user._id
});
if (other == 0) {
@@ -72,14 +72,14 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// 以前のセッションはすべて削除しておく
await Matching.remove({
- parent_id: user._id
+ parentId: user._id
});
// セッションを作成
const matching = await Matching.insert({
- created_at: new Date(),
- parent_id: user._id,
- child_id: child._id
+ createdAt: new Date(),
+ parentId: user._id,
+ childId: child._id
});
// Reponse
diff --git a/src/server/api/endpoints/othello/match/cancel.ts b/src/server/api/endpoints/othello/match/cancel.ts
index 6f751ef835..ee0f82a611 100644
--- a/src/server/api/endpoints/othello/match/cancel.ts
+++ b/src/server/api/endpoints/othello/match/cancel.ts
@@ -2,7 +2,7 @@ import Matching from '../../../models/othello-matching';
module.exports = (params, user) => new Promise(async (res, rej) => {
await Matching.remove({
- parent_id: user._id
+ parentId: user._id
});
res();