From d150c7e2ec506b8be471797bbbcba1338bc0ccfe Mon Sep 17 00:00:00 2001
From: Taiite <hubert.hirtz@laposte.net>
Date: Fri, 12 Oct 2018 16:26:42 +0200
Subject: [PATCH] KISS2

---
 api/games/games.ts | 61 ++++++++++------------------------------------
 1 file changed, 13 insertions(+), 48 deletions(-)

diff --git a/api/games/games.ts b/api/games/games.ts
index a967dc7..1b1c1a7 100644
--- a/api/games/games.ts
+++ b/api/games/games.ts
@@ -89,26 +89,12 @@ export const joinGame = new ValidatedMethod<{ _id: string }, void>({
   }
 })
 
-export const nextCards = new ValidatedMethod<{}, void>({
-  name: 'Game.nextCards',
-  mixins: [schemaMixin, loggedInMixin, inGameMixin],
-  validate: new SimpleSchema({}),
-  run () {
-    callSystem(this, this.game.sys.nextCards)
-  }
-})
+export const nextCards = newGameMethod('nextCards')
 
-export const giveCards = new ValidatedMethod<{ cards: Card[] }, void>({
-  name: 'Game.giveCards',
-  mixins: [schemaMixin, loggedInMixin, inGameMixin],
-  validate: new SimpleSchema({
-    cards: {type: Array, minCount: 3, maxCount: 3},
-    'cards.$': Card
-  }),
-  run ({cards}) {
-    callSystem(this, this.game.sys.giveCards, cards)
-  }
-})
+export const giveCards = newGameMethod('giveCards', new SimpleSchema({
+  cards: {type: Array, minCount: 3, maxCount: 3},
+  'cards.$': Card
+}), 'cards')
 
 export const playCards = new ValidatedMethod({
   name: 'Game.playCards',
@@ -135,38 +121,17 @@ export const playCards = new ValidatedMethod({
   }
 })
 
-export const skipTurn = new ValidatedMethod<{}, void>({
-  name: 'Game.skipTurn',
-  mixins: [schemaMixin, loggedInMixin, inGameMixin],
-  validate: new SimpleSchema({}),
-  run () {
-    callSystem(this, this.game.sys.skipTurn)
-  }
-})
+export const skipTurn = newGameMethod('skipTurn')
 
-export const giveDragon = new ValidatedMethod<{ to: number }, void>({
-  name: 'game.giveDragon',
-  mixins: [schemaMixin, loggedInMixin, inGameMixin],
-  validate: new SimpleSchema({
-    to: {type: Number, allowedValues: [0, 1]}
-  }),
-  run ({to}) {
-    callSystem(this, this.game.sys.giveDragon, to)
-  }
-})
+export const giveDragon = newGameMethod('giveDragon', new SimpleSchema({
+  to: {type: Number, allowedValues: [0, 1]}
+}), 'to')
 
-export const makeCall = new ValidatedMethod<{ bet: number }, void>({
-  name: 'Game.makeCall',
-  mixins: [schemaMixin, loggedInMixin, inGameMixin],
-  validate: new SimpleSchema({
-    bet: {type: Number, allowedValues: [Bet.TICHU, Bet.GRAND]}
-  }),
-  run ({bet}) {
-    callSystem(this, this.game.sys.makeCall, bet)
-  }
-})
+export const makeCall = newGameMethod('makeCall', new SimpleSchema({
+  bet: {type: Number, allowedValues: [Bet.TICHU, Bet.GRAND]}
+}), 'bet')
 
-function newGameMethod (name: string, schema: SimpleSchema, argName?: string): ValidatedMethod<any, void> {
+function newGameMethod (name: string, schema: SimpleSchema = new SimpleSchema({}), argName?: string): ValidatedMethod<any, void> {
   return new ValidatedMethod<any, void>({
     name: 'Game.' + name,
     mixins: [schemaMixin, loggedInMixin, inGameMixin],
-- 
GitLab