diff --git a/package.json b/package.json index fa66a06..81e7695 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "menheraapi", - "version": "5.3.0", + "version": "5.3.1", "description": "An HTTP API to help MenheraBot", "main": "dist/server.js", "private": true, diff --git a/src/data/controllers/FarmController.ts b/src/data/controllers/FarmController.ts index b1e893b..1e68cf0 100644 --- a/src/data/controllers/FarmController.ts +++ b/src/data/controllers/FarmController.ts @@ -14,6 +14,27 @@ export default class FarmController { return res.sendStatus(201); } + public static async postMultipleHarvest(req: Request, res: Response): Promise { + const { userId, plants } = req.body; + if (!userId || typeof plants === 'undefined') { + return res.sendStatus(400); + } + + plants.reduce((p, c) => { + if (!p[c.plant]) p[c.plant] = 0; + + p[c.plant] += 1; + + return p; + }, {}); + + Object.entries(plants).forEach(([plant, amount]) => { + registerFarmAction(userId, Number(plant), 'HARVEST', Number(amount)); + }); + + return res.sendStatus(201); + } + public static async getFarmerData(req: Request, res: Response): Promise { const { userId } = req.query; diff --git a/src/data/controllers/JogoDoBichoController.ts b/src/data/controllers/JogoDoBichoController.ts index 8f9ce89..710fe4f 100644 --- a/src/data/controllers/JogoDoBichoController.ts +++ b/src/data/controllers/JogoDoBichoController.ts @@ -50,9 +50,6 @@ export default class JogoDoBichoController { if (numberPage < 1) return res.status(422).json({ message: 'The page must be grather than 0' }); - if (numberPage >= 100) - return res.status(422).json({ message: 'The page must be less than 100' }); - const results = await getBichoHistory(numberPage); return res.status(200).json(results); diff --git a/src/data/database/DatabaseQueries.ts b/src/data/database/DatabaseQueries.ts index 265307f..01a59b6 100644 --- a/src/data/database/DatabaseQueries.ts +++ b/src/data/database/DatabaseQueries.ts @@ -247,7 +247,6 @@ export const registerBichoGame = async ( results: string ): Promise => { await Prisma.bichogames.create({ - // @ts-expect-error This conversion is bad data: { date, players: users, results }, }); }; @@ -261,7 +260,6 @@ export const getBichoHistory = async (page: number): Promise => { orderBy: { id: 'desc' }, }); - // @ts-expect-error Bigint to Number return result.map(a => ({ ...a, date: Number(a.date), results: JSON.parse(a.results) })); }; @@ -643,7 +641,8 @@ export const getTransactions = async ( export const registerFarmAction = async ( userId: string, plant: number, - action: 'HARVEST' | 'ROTTED' + action: 'HARVEST' | 'ROTTED', + amount = 1 ): Promise => { await Redis.ensureUsers(userId); @@ -654,11 +653,11 @@ export const registerFarmAction = async ( plant, }, }, - update: { [action.toLowerCase()]: { increment: 1 } }, + update: { [action.toLowerCase()]: { increment: amount } }, create: { user_id: userId, plant, - [action.toLowerCase()]: 1, + [action.toLowerCase()]: amount, }, }); }; diff --git a/src/data/routes.ts b/src/data/routes.ts index d0ca2e7..bb41936 100644 --- a/src/data/routes.ts +++ b/src/data/routes.ts @@ -43,6 +43,7 @@ StatisticsGroup.post('/transaction', TransactionsController.postTransaction); // Fazendinha Command StatisticsGroup.get('/fazendinha', FarmController.getFarmerData); StatisticsGroup.post('/fazendinha', FarmController.postAction); +StatisticsGroup.post('/fazendinha-harvest', FarmController.postMultipleHarvest); StatisticsGroup.get('/fazendinha/top', FarmController.topFarmer); // Rock Paper Scissors Command; StatisticsGroup.get( diff --git a/yarn.lock b/yarn.lock index ab812ad..0ac1a11 100644 --- a/yarn.lock +++ b/yarn.lock @@ -553,9 +553,9 @@ create-require@^1.1.0: integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ== cross-spawn@^7.0.2: - version "7.0.3" - resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" - integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w== + version "7.0.6" + resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.6.tgz#8a58fe78f00dcd70c370451759dfbfaf03e8ee9f" + integrity sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA== dependencies: path-key "^3.1.0" shebang-command "^2.0.0"