Yosif Stalin Gaming
Yosif Stalin Gaming
TTCTheo's Typesafe Cult
Created by Yosif Stalin Gaming on 3/5/2024 in #questions
prisma create code architecture
Hi guys I am relatively new to prisma amd I am wondering is this the correct way to use the create directive since it seems the code will be slower than an alternative Also I am talking about the add session
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

class DB {
// Method to create a user
async createUser(name: string, email: string | null = null) {
try {
const newUser = await prisma.user.create({
data: {
name: name,
email: email,
is_premium: false,
sessions: {
create: []
}
}
});
return newUser;
} catch (error) {
console.error("Error creating user:", error);
throw error;
}
}

// Method to add session to a user
async addSession(userId: number, session: { creation_date: Date, baseSnapshotId: number }) {
try {
const updatedUser = await prisma.user.update({
where: { id: userId },
data: {
sessions: {
create: {
creation_date: session.creation_date,
baseSnapshotId: session.baseSnapshotId
}
}
},
include: {
sessions: true
}
});
return updatedUser;
} catch (error) {
console.error("Error adding session to user:", error);
throw error;
}
}
}
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

class DB {
// Method to create a user
async createUser(name: string, email: string | null = null) {
try {
const newUser = await prisma.user.create({
data: {
name: name,
email: email,
is_premium: false,
sessions: {
create: []
}
}
});
return newUser;
} catch (error) {
console.error("Error creating user:", error);
throw error;
}
}

// Method to add session to a user
async addSession(userId: number, session: { creation_date: Date, baseSnapshotId: number }) {
try {
const updatedUser = await prisma.user.update({
where: { id: userId },
data: {
sessions: {
create: {
creation_date: session.creation_date,
baseSnapshotId: session.baseSnapshotId
}
}
},
include: {
sessions: true
}
});
return updatedUser;
} catch (error) {
console.error("Error adding session to user:", error);
throw error;
}
}
}
The method I think will be faster is to directly create a session and link it to a user
2 replies
TTCTheo's Typesafe Cult
Created by Yosif Stalin Gaming on 6/4/2023 in #questions
ENV ERROR VRECEL
❌ Invalid environment variables: { Github_CLIENT_ID: [ 'Required' ], Github_CLIENT_SECRET: [ 'Required' ] } error - Failed to load next.config.mjs, see more info here https://nextjs.org/docs/messages/next-config-error
Build error occurred
Error: Invalid environment variables at f (file:///vercel/path0/frontend/node_modules/@t3-oss/env-nextjs/dist/index.mjs:1:505) at l (file:///vercel/path0/frontend/node_modules/@t3-oss/env-nextjs/dist/index.mjs:1:695) at C (file:///vercel/path0/frontend/node_modules/@t3-oss/env-nextjs/dist/index.mjs:1:868) at file:///vercel/path0/frontend/src/env.mjs:4:20 at ModuleJob.run (node:internal/modules/esm/module_job:194:25) Error: Command "npm run build" exited with 1 BUILD_UTILS_SPAWN_1: Command "npm run build" exited with 1 What am i doing wrong? i have added all envs in vercel and the env.mjs
2 replies
TTCTheo's Typesafe Cult
Created by Yosif Stalin Gaming on 6/1/2023 in #questions
How to sent a mutation procedure from the client
updateUserStats:protectedProcedure .input(z.object({ id:z.string().nonempty(), protein:z.number().int(), carbs:z.number().int(), fats:z.number().int(), calories:z.number().int(), })) .mutation(({ctx,input}) => { const {id,protein,carbs,fats,calories} = input; return ctx.prisma.foodStats.update({ where:{ userId:id }, data:{ protein, carbs, fats, calories } }) }) if thats the backend function how should i send a req from the client api.user.updateUserStats.useMutation({ data:{ calories:cals + formData.calories, protein:rawUserStats.protein + formData.protein, carbs:rawUserStats.carbs + formData.carbs, fats:rawUserStats.fat + formData.fat }, }) something like this
11 replies