Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
21 changes: 21 additions & 0 deletions src/data/controllers/FarmController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@ export default class FarmController {
return res.sendStatus(201);
}

public static async postMultipleHarvest(req: Request, res: Response): Promise<Response> {
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<Response> {
const { userId } = req.query;

Expand Down
3 changes: 0 additions & 3 deletions src/data/controllers/JogoDoBichoController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 4 additions & 5 deletions src/data/database/DatabaseQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ export const registerBichoGame = async (
results: string
): Promise<void> => {
await Prisma.bichogames.create({
// @ts-expect-error This conversion is bad
data: { date, players: users, results },
});
};
Expand All @@ -261,7 +260,6 @@ export const getBichoHistory = async (page: number): Promise<bichogames[]> => {
orderBy: { id: 'desc' },
});

// @ts-expect-error Bigint to Number
return result.map(a => ({ ...a, date: Number(a.date), results: JSON.parse(a.results) }));
};

Expand Down Expand Up @@ -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<void> => {
await Redis.ensureUsers(userId);

Expand All @@ -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,
},
});
};
Expand Down
1 change: 1 addition & 0 deletions src/data/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading