Ayato
Ayato
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Ayato on 6/14/2023 in #questions
YouTube Data API
Ohh yea, that worked, thank you very much, do you know why the above method works for some but not for all?
7 replies
TTCTheo's Typesafe Cult
Created by Ayato on 4/17/2023 in #questions
tRPC Mutation
Ahh, thanks
7 replies
TTCTheo's Typesafe Cult
Created by Ayato on 4/15/2023 in #questions
<Select onChange()>
Thanks
4 replies
TTCTheo's Typesafe Cult
Created by Ayato on 4/13/2023 in #questions
typescript-eslint
2 replies
TTCTheo's Typesafe Cult
Created by Ayato on 4/5/2023 in #questions
findUnique from current user
I will take a look
11 replies
TTCTheo's Typesafe Cult
Created by Ayato on 4/4/2023 in #questions
getById from current user
41 replies
TTCTheo's Typesafe Cult
Created by Ayato on 4/5/2023 in #questions
findUnique from current user
yes, but if another user gets the id he could delete it. Is that securety wise ok?
11 replies
TTCTheo's Typesafe Cult
Created by Ayato on 4/5/2023 in #questions
findUnique from current user
I think findFirst sounds fine, but it is getting worse, when we get to update or delete, because I would have to use deleteMany to put in multiple filter.
// Delete a deposit by id for the current user
delete: protectedProcedure
.input(z.object({ id: z.string() }))
.query(async ({ ctx, input }) => {
const deposit = await ctx.prisma.deposit.deleteMany({
where: {
id: input.id,
userId: ctx.session.user.id,
},
});
return deposit;
}),
// Delete a deposit by id for the current user
delete: protectedProcedure
.input(z.object({ id: z.string() }))
.query(async ({ ctx, input }) => {
const deposit = await ctx.prisma.deposit.deleteMany({
where: {
id: input.id,
userId: ctx.session.user.id,
},
});
return deposit;
}),
11 replies
TTCTheo's Typesafe Cult
Created by Ayato on 4/4/2023 in #questions
getById from current user
yes ofc, but it feels a but sloppy, just because I know the id of a privat massage of yours I don't think I could request it.
41 replies
TTCTheo's Typesafe Cult
Created by Ayato on 4/4/2023 in #questions
getById from current user
I think I will just go with this, if you have any better ideas please tell me:
getById: protectedProcedure
.input(z.object({ id: z.string() }))
.query(async ({ ctx, input }) => {
const deposit = await ctx.prisma.deposit.findFirst({
where: {
id: input.id,
userId: ctx.session.user.id,
},
});
return deposit;
}),
getById: protectedProcedure
.input(z.object({ id: z.string() }))
.query(async ({ ctx, input }) => {
const deposit = await ctx.prisma.deposit.findFirst({
where: {
id: input.id,
userId: ctx.session.user.id,
},
});
return deposit;
}),
41 replies
TTCTheo's Typesafe Cult
Created by Ayato on 4/4/2023 in #questions
getById from current user
OK, I checked it and it do is like I thaght: server:
getById: protectedProcedure
.input(z.object({ id: z.string() }))
.query(async ({ ctx, input }) => {
const deposit = await ctx.prisma.deposit.findUnique({
where: {
id: input.id,
},
});
return deposit;
}),
getById: protectedProcedure
.input(z.object({ id: z.string() }))
.query(async ({ ctx, input }) => {
const deposit = await ctx.prisma.deposit.findUnique({
where: {
id: input.id,
},
});
return deposit;
}),
client:
const { data } = api.deposit.getById.useQuery({id: "clg2ppm4u0000n5fstlpwqb2f"});
console.log(data);
const { data } = api.deposit.getById.useQuery({id: "clg2ppm4u0000n5fstlpwqb2f"});
console.log(data);
I'm logged in as user 1 but the deposit.id is of a deposit from another user.
41 replies
TTCTheo's Typesafe Cult
Created by Ayato on 4/4/2023 in #questions
getById from current user
alright, thanks for your help @Diogovski
41 replies
TTCTheo's Typesafe Cult
Created by Ayato on 4/4/2023 in #questions
getById from current user
Yea, but theoretical if you have the ID you can get the deposit from a another user right?
41 replies
TTCTheo's Typesafe Cult
Created by Ayato on 4/4/2023 in #questions
getById from current user
it is not giving me an error
41 replies
TTCTheo's Typesafe Cult
Created by Ayato on 4/4/2023 in #questions
getById from current user
do you think this would do?
getById: protectedProcedure
.input(z.object({ id: z.string() }))
.query(async ({ ctx, input }) => {
const where = {
id: input.id,
userId: ctx.session.user.id,
};
const deposit = await ctx.prisma.deposit.findUnique({
where,
});
return deposit;
}),
getById: protectedProcedure
.input(z.object({ id: z.string() }))
.query(async ({ ctx, input }) => {
const where = {
id: input.id,
userId: ctx.session.user.id,
};
const deposit = await ctx.prisma.deposit.findUnique({
where,
});
return deposit;
}),
41 replies
TTCTheo's Typesafe Cult
Created by Ayato on 4/4/2023 in #questions
getById from current user
ohh, but this btw. is also not working:
getById: protectedProcedure
.input(z.object({ id: z.string() }))
.query(async ({ ctx, input }) => {
const deposit = await ctx.prisma.deposit.findUnique({
where: {
userId: ctx.session.user.id
},
});
return deposit;
}),
getById: protectedProcedure
.input(z.object({ id: z.string() }))
.query(async ({ ctx, input }) => {
const deposit = await ctx.prisma.deposit.findUnique({
where: {
userId: ctx.session.user.id
},
});
return deposit;
}),
maybe because it is not nnique
41 replies
TTCTheo's Typesafe Cult
Created by Ayato on 4/4/2023 in #questions
getById from current user
41 replies
TTCTheo's Typesafe Cult
Created by Ayato on 4/4/2023 in #questions
getById from current user
41 replies
TTCTheo's Typesafe Cult
Created by Ayato on 4/4/2023 in #questions
getById from current user
but as I said, getAll works fine
41 replies
TTCTheo's Typesafe Cult
Created by Ayato on 4/4/2023 in #questions
getById from current user
model Deposit {
id String @id @default(cuid())
userId String
deposit_type depositTypes
name String
description String?
balance Float
created_at DateTime @default(now())
updated_at DateTime @default(now()) @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
expenses Expense[]
revenues Revenue[]
fromTransfers Transfer[] @relation("from_Deposit")
toTransfers Transfer[] @relation("to_Deposit")

@@index([userId])
}
model Deposit {
id String @id @default(cuid())
userId String
deposit_type depositTypes
name String
description String?
balance Float
created_at DateTime @default(now())
updated_at DateTime @default(now()) @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
expenses Expense[]
revenues Revenue[]
fromTransfers Transfer[] @relation("from_Deposit")
toTransfers Transfer[] @relation("to_Deposit")

@@index([userId])
}
41 replies