Need help with relations
Im not sure why this is throwing an error but it won't let me make my query
const token = await db.query.emailTokens.findFirst({
where: (token, { eq }) => eq(token.token_hash, tokenId)
});
if (!token || token.expiresAt < new Date()) {
return message(form, 'Token is invalid or has expired. Please request a new one.', {
status: 404
});
}
const user = await db.query.users.findFirst({
with: {
emailTokens: {
where: (emailTokens, { eq }) => eq(emailTokens.userId, token.userId)
}
}
});
Object literal may only specify known properties, and 'where' does not exist in type '{ columns?: { id?: boolean | undefined; userId?: boolean | undefined; token_hash?: boolean | undefined; expiresAt?: boolean | undefined; type?: boolean | undefined; } | undefined; with?: {} | undefined; extras?: Record<...> | ... 1 more ... | undefined; }'.ts(2353)
const token = await db.query.emailTokens.findFirst({
where: (token, { eq }) => eq(token.token_hash, tokenId)
});
if (!token || token.expiresAt < new Date()) {
return message(form, 'Token is invalid or has expired. Please request a new one.', {
status: 404
});
}
const user = await db.query.users.findFirst({
with: {
emailTokens: {
where: (emailTokens, { eq }) => eq(emailTokens.userId, token.userId)
}
}
});
Object literal may only specify known properties, and 'where' does not exist in type '{ columns?: { id?: boolean | undefined; userId?: boolean | undefined; token_hash?: boolean | undefined; expiresAt?: boolean | undefined; type?: boolean | undefined; } | undefined; with?: {} | undefined; extras?: Record<...> | ... 1 more ... | undefined; }'.ts(2353)
export const users = pgTable('users', {
id: text('id').primaryKey(),
email: text('email').unique().notNull().unique(),
hashed_password: text('hashed_password'),
role: userRoleEnum('role'),
status: userStatusEnum('status')
});
export const emailTokens = pgTable('email_tokens', {
id: serial('id').primaryKey(),
userId: text('userId'),
token_hash: text('token').unique().notNull(),
expiresAt: timestamp('expiresAt').notNull(),
type: emailTokenEnum('type')
});
export const usersRelations = relations(users, ({ one }) => ({
settings: one(settings, {
fields: [users.id],
references: [settings.user_id]
}),
emailTokens: one(emailTokens, {
fields: [users.id],
references: [emailTokens.userId]
})
}));
export const users = pgTable('users', {
id: text('id').primaryKey(),
email: text('email').unique().notNull().unique(),
hashed_password: text('hashed_password'),
role: userRoleEnum('role'),
status: userStatusEnum('status')
});
export const emailTokens = pgTable('email_tokens', {
id: serial('id').primaryKey(),
userId: text('userId'),
token_hash: text('token').unique().notNull(),
expiresAt: timestamp('expiresAt').notNull(),
type: emailTokenEnum('type')
});
export const usersRelations = relations(users, ({ one }) => ({
settings: one(settings, {
fields: [users.id],
references: [settings.user_id]
}),
emailTokens: one(emailTokens, {
fields: [users.id],
references: [emailTokens.userId]
})
}));
0 Replies