This commit is contained in:
Daniel 2023-08-05 22:07:55 -04:00
commit aeb88def6d
2 changed files with 20 additions and 16 deletions

View File

@ -50,9 +50,11 @@ export default async function updateUser(
email: user.email?.toLowerCase(), email: user.email?.toLowerCase(),
}, },
] ]
: { : [
username: user.username.toLowerCase(), {
}, username: user.username.toLowerCase(),
},
],
}, },
}); });
@ -112,27 +114,29 @@ export default async function updateUser(
: undefined, : undefined,
}, },
include: { include: {
whitelistedUsers: true whitelistedUsers: true,
} },
}); });
const { whitelistedUsers, password, ...userInfo } = updatedUser; const { whitelistedUsers, password, ...userInfo } = updatedUser;
// If user.whitelistedUsers is not provided, we will assume the whitelistedUsers should be removed // If user.whitelistedUsers is not provided, we will assume the whitelistedUsers should be removed
const newWhitelistedUsernames: string[] = user.whitelistedUsers || []; const newWhitelistedUsernames: string[] = user.whitelistedUsers || [];
// Get the current whitelisted usernames // Get the current whitelisted usernames
const currentWhitelistedUsernames: string[] = whitelistedUsers.map((user) => user.username); const currentWhitelistedUsernames: string[] = whitelistedUsers.map(
(user) => user.username
);
// Find the usernames to be deleted (present in current but not in new) // Find the usernames to be deleted (present in current but not in new)
const usernamesToDelete: string[] = currentWhitelistedUsernames.filter( const usernamesToDelete: string[] = currentWhitelistedUsernames.filter(
(username) => !newWhitelistedUsernames.includes(username) (username) => !newWhitelistedUsernames.includes(username)
); );
// Find the usernames to be created (present in new but not in current) // Find the usernames to be created (present in new but not in current)
const usernamesToCreate: string[] = newWhitelistedUsernames.filter( const usernamesToCreate: string[] = newWhitelistedUsernames.filter(
(username) => !currentWhitelistedUsernames.includes(username) && username.trim() !== '' (username) =>
!currentWhitelistedUsernames.includes(username) && username.trim() !== ""
); );
// Delete whitelistedUsers that are not present in the new list // Delete whitelistedUsers that are not present in the new list
@ -155,7 +159,6 @@ export default async function updateUser(
}); });
} }
const STRIPE_SECRET_KEY = process.env.STRIPE_SECRET_KEY; const STRIPE_SECRET_KEY = process.env.STRIPE_SECRET_KEY;
const PRICE_ID = process.env.PRICE_ID; const PRICE_ID = process.env.PRICE_ID;

View File

@ -10,9 +10,10 @@ export const prisma =
if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma; if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
if (process.env.NODE_ENV !== "production") // For benchmarking | uncomment when needed
prisma.$on("query" as any, (e: any) => { // if (process.env.NODE_ENV !== "production")
console.log("Query: " + e.query); // prisma.$on("query" as any, (e: any) => {
console.log("Params: " + e.params); // console.log("Query: " + e.query);
console.log("\x1b[31m", `Duration: ${e.duration}ms`, "\x1b[0m"); // For benchmarking // console.log("Params: " + e.params);
}); // console.log("\x1b[31m", `Duration: ${e.duration}ms`, "\x1b[0m");
// });