mirror of
https://github.com/spliit-app/spliit.git
synced 2025-12-06 09:29:39 +01:00
Loading screens & layouts
This commit is contained in:
@@ -4,7 +4,8 @@ import { Expense } from '@prisma/client'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
|
||||
export async function createGroup(groupFormValues: GroupFormValues) {
|
||||
return getPrisma().group.create({
|
||||
const prisma = await getPrisma()
|
||||
return prisma.group.create({
|
||||
data: {
|
||||
id: uuidv4(),
|
||||
name: groupFormValues.name,
|
||||
@@ -36,7 +37,8 @@ export async function createExpense(
|
||||
throw new Error(`Invalid participant ID: ${participant}`)
|
||||
}
|
||||
|
||||
return getPrisma().expense.create({
|
||||
const prisma = await getPrisma()
|
||||
return prisma.expense.create({
|
||||
data: {
|
||||
id: uuidv4(),
|
||||
groupId,
|
||||
@@ -73,7 +75,8 @@ export async function updateExpense(
|
||||
throw new Error(`Invalid participant ID: ${participant}`)
|
||||
}
|
||||
|
||||
return getPrisma().expense.update({
|
||||
const prisma = await getPrisma()
|
||||
return prisma.expense.update({
|
||||
where: { id: expenseId },
|
||||
data: {
|
||||
amount: expenseFormValues.amount,
|
||||
@@ -104,7 +107,8 @@ export async function updateGroup(
|
||||
const existingGroup = await getGroup(groupId)
|
||||
if (!existingGroup) throw new Error('Invalid group ID')
|
||||
|
||||
return getPrisma().group.update({
|
||||
const prisma = await getPrisma()
|
||||
return prisma.group.update({
|
||||
where: { id: groupId },
|
||||
data: {
|
||||
name: groupFormValues.name,
|
||||
@@ -134,21 +138,24 @@ export async function updateGroup(
|
||||
}
|
||||
|
||||
export async function getGroup(groupId: string) {
|
||||
return getPrisma().group.findUnique({
|
||||
const prisma = await getPrisma()
|
||||
return prisma.group.findUnique({
|
||||
where: { id: groupId },
|
||||
include: { participants: true },
|
||||
})
|
||||
}
|
||||
|
||||
export async function getGroupExpenses(groupId: string) {
|
||||
return getPrisma().expense.findMany({
|
||||
const prisma = await getPrisma()
|
||||
return prisma.expense.findMany({
|
||||
where: { groupId },
|
||||
include: { paidFor: { include: { participant: true } }, paidBy: true },
|
||||
})
|
||||
}
|
||||
|
||||
export async function getExpense(groupId: string, expenseId: string) {
|
||||
return getPrisma().expense.findUnique({
|
||||
const prisma = await getPrisma()
|
||||
return prisma.expense.findUnique({
|
||||
where: { id: expenseId },
|
||||
include: { paidBy: true, paidFor: true },
|
||||
})
|
||||
|
||||
@@ -2,7 +2,7 @@ import { PrismaClient } from '@prisma/client'
|
||||
|
||||
let prisma: PrismaClient
|
||||
|
||||
export function getPrisma() {
|
||||
export async function getPrisma() {
|
||||
if (!prisma) {
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
prisma = new PrismaClient()
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { type ClassValue, clsx } from "clsx"
|
||||
import { twMerge } from "tailwind-merge"
|
||||
|
||||
import { clsx, type ClassValue } from 'clsx'
|
||||
import { twMerge } from 'tailwind-merge'
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
|
||||
export function delay(ms: number) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user