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
33 changes: 17 additions & 16 deletions Backend/src/controllers/game.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import ApiResponse from "../utils/ApiResponse.js";
import { Game } from "../models/gameId.models.js";

const addBgmiId = asyncHandler(async (req, res) => {
const { bgmiId } = req.body;
const { gameID } = req.body;

const user = req.user;
if (!bgmiId) {
if (!gameID) {
throw new ApiError(400, "All Fields Are Required.");
}
try {
await Game.findOneAndUpdate(
{ owner: user._id },
{ bgmiId: bgmiId },
{ bgmiId: gameID },
{ new: true }
);
return res
Expand All @@ -24,15 +25,15 @@ const addBgmiId = asyncHandler(async (req, res) => {
});

const addFreeFireId = asyncHandler(async (req, res) => {
const { freeFireId } = req.body;
const { gameID } = req.body;
const user = req.user;
if (!freeFireId) {
if (!gameID) {
throw new ApiError(400, "All Fields Are Required.");
}
try {
await Game.findOneAndUpdate(
{ owner: user._id },
{ freefireId: freeFireId },
{ freefireId: gameID },
{ new: true }
);
return res
Expand All @@ -44,18 +45,18 @@ const addFreeFireId = asyncHandler(async (req, res) => {
});

const addValorantId = asyncHandler(async (req, res) => {
const { valorantId } = req.body;
const { gameID } = req.body;
const user = req.user;
if (!valorantId.tagline || !valorantId.riotId) {
if (!gameID.tagline || !gameID.riotId) {
throw new ApiError(400, "All Fields Are Required.");
}
try {
await Game.findOneAndUpdate(
{ owner: user._id },
{
valorantId: {
riotId: valorantId.riotId,
tagline: valorantId.tagline
riotId: gameID.riotId,
tagline: gameID.tagline
}
},
{ new: true }
Expand All @@ -69,15 +70,15 @@ const addValorantId = asyncHandler(async (req, res) => {
});

const addCodmId = asyncHandler(async (req, res) => {
const { codmId } = req.body;
const { gameID } = req.body;
const user = req.user;
if (!codmId) {
if (!gameID) {
throw new ApiError(400, "All Fields Are Required.");
}
try {
await Game.findOneAndUpdate(
{ owner: user._id },
{ codmId: codmId },
{ codmId: gameID },
{ new: true }
);
return res
Expand All @@ -89,15 +90,15 @@ const addCodmId = asyncHandler(async (req, res) => {
});

const addAsphaltId = asyncHandler(async (req, res) => {
const { asphaltId } = req.body;
const { gameID } = req.body;
const user = req.user;
if (!asphaltId) {
if (!gameID) {
throw new ApiError(400, "All Fields Are Required.");
}
try {
await Game.findOneAndUpdate(
{ owner: user._id },
{ asphaltId: asphaltId },
{ asphaltId: gameID },
{ new: true }
);
return res
Expand Down
10 changes: 5 additions & 5 deletions Backend/src/utils/zodSchema/gameValidatorSchema.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { z } from "zod";

const bgmiIdSchema = z.object({
bgmiId: z.string().min(1, { message: "Bgmi Id is required" }),
gameID: z.string().min(1, { message: "Bgmi Id is required" }),
});

const freeFireIdSchema = z.object({
freeFireId: z.string().min(1, { message: "FreeFire Id is required" }),
gameID: z.string().min(1, { message: "FreeFire Id is required" }),
});

const valorantIdSchema = z.object({
valorantId: z.object({
gameID: z.object({
riotId: z.string().min(1, { message: "Riot Id is required" }),
tagline: z.string().min(1, { message: "Tagline is required" }),
}),
});

const codmIdSchema = z.object({
codmId: z.string().min(1, { message: "Codm Id is required" }),
gameID: z.string().min(1, { message: "Codm Id is required" }),
});

const asphaltIdSchema = z.object({
asphaltId: z.string().min(1, { message: "Asphalt Id is required" }),
gameID: z.string().min(1, { message: "Asphalt Id is required" }),
});

export {
Expand Down