mirror of
https://github.com/ArthurDanjou/arthome.git
synced 2026-01-14 12:14:33 +01:00
Working
This commit is contained in:
@@ -3,8 +3,8 @@ import { serial, timestamp } from 'drizzle-orm/pg-core'
|
||||
* A centralized list of standardized Drizzle ORM schema field definitions to prevent duplication errors
|
||||
*/
|
||||
|
||||
export const createdAt = timestamp('created_at', { mode: 'date', precision: 3 }).defaultNow()
|
||||
export const updatedAt = timestamp('updated_at', { mode: 'date', precision: 3 }).$onUpdate(() => new Date())
|
||||
export const createdAt = timestamp('created_at', { mode: 'string', withTimezone: true, precision: 0 }).defaultNow()
|
||||
export const updatedAt = timestamp('updated_at', { mode: 'string', withTimezone: true, precision: 0 }).defaultNow().$onUpdateFn(() => sql`(current_timestamp)`)
|
||||
export const id = serial('id').primaryKey()
|
||||
|
||||
export const timestamps = {
|
||||
|
||||
@@ -1,15 +1,6 @@
|
||||
import type { SQL } from 'drizzle-orm'
|
||||
import type { UserInsert } from '~~/server/utils/db'
|
||||
|
||||
export async function findUserById(userId: number) {
|
||||
return useDrizzle()
|
||||
.query
|
||||
.users
|
||||
.findFirst({
|
||||
where: eq(tables.users.id, userId),
|
||||
})
|
||||
}
|
||||
|
||||
export async function findUserByGitHubId(githubId: number) {
|
||||
return useDrizzle()
|
||||
.query
|
||||
@@ -41,18 +32,21 @@ export async function createUser(user: UserInsert) {
|
||||
return useDrizzle()
|
||||
.insert(tables.users)
|
||||
.values(user)
|
||||
.onConflictDoNothing()
|
||||
.returning()
|
||||
}
|
||||
|
||||
export async function updateUser(userId: number, user: Partial<UserInsert>) {
|
||||
await useDrizzle()
|
||||
.update(tables.users)
|
||||
.set(user)
|
||||
.set({
|
||||
...user,
|
||||
})
|
||||
.where(eq(tables.users.id, userId))
|
||||
}
|
||||
|
||||
export async function deleteProfilePicture(avatar: string) {
|
||||
if (avatar.startsWith('avatars/')) {
|
||||
if (avatar.startsWith('avatars')) {
|
||||
await hubBlob().del(avatar)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user