commit
51902d779e
17 changed files with 82 additions and 66 deletions
|
@ -7,7 +7,7 @@ import { Label } from '@/components/ui/label';
|
|||
import { Input } from '@/components/ui/input';
|
||||
import { URL_SIGN_IN } from '@/lib/constants';
|
||||
import generateSampleData from '@/lib/actions/generateSampleData';
|
||||
import { prismaClient } from '@/prisma';
|
||||
import prisma from '@/prisma';
|
||||
import { ServerActionTrigger } from '@/components/form/serverActionTrigger';
|
||||
import accountDelete from '@/lib/actions/accountDelete';
|
||||
|
||||
|
@ -20,21 +20,21 @@ export default async function AccountPage() {
|
|||
}
|
||||
|
||||
let paymentCount = 0;
|
||||
paymentCount = await prismaClient.payment.count({
|
||||
paymentCount = await prisma.payment.count({
|
||||
where: {
|
||||
userId: user.id,
|
||||
},
|
||||
});
|
||||
|
||||
let entityCount = 0;
|
||||
entityCount = await prismaClient.entity.count({
|
||||
entityCount = await prisma.entity.count({
|
||||
where: {
|
||||
userId: user.id,
|
||||
},
|
||||
});
|
||||
|
||||
let categoryCount = 0;
|
||||
categoryCount = await prismaClient.category.count({
|
||||
categoryCount = await prisma.category.count({
|
||||
where: {
|
||||
userId: user.id,
|
||||
},
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { getUser } from '@/auth';
|
||||
import { prismaClient } from '@/prisma';
|
||||
import prisma from '@/prisma';
|
||||
import React from 'react';
|
||||
import CategoryPageClientContent from '@/components/categoryPageClientComponents';
|
||||
import categoryCreateUpdate from '@/lib/actions/categoryCreateUpdate';
|
||||
|
@ -9,7 +9,7 @@ export default async function CategoriesPage() {
|
|||
|
||||
const user = await getUser();
|
||||
|
||||
const categories = await prismaClient.category.findMany({
|
||||
const categories = await prisma.category.findMany({
|
||||
where: {
|
||||
userId: user?.id,
|
||||
},
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { prismaClient } from '@/prisma';
|
||||
import prisma from '@/prisma';
|
||||
import { getUser } from '@/auth';
|
||||
import React from 'react';
|
||||
import EntityPageClientContent from '@/components/entityPageClientComponents';
|
||||
|
@ -9,7 +9,7 @@ export default async function EntitiesPage() {
|
|||
|
||||
const user = await getUser();
|
||||
|
||||
const entities = await prismaClient.entity.findMany({
|
||||
const entities = await prisma.entity.findMany({
|
||||
where: {
|
||||
userId: user?.id,
|
||||
},
|
||||
|
@ -23,7 +23,7 @@ export default async function EntitiesPage() {
|
|||
],
|
||||
});
|
||||
|
||||
const categories = await prismaClient.category.findMany({
|
||||
const categories = await prisma.category.findMany({
|
||||
where: {
|
||||
userId: user?.id,
|
||||
},
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import React from 'react';
|
||||
import { Category, Entity, EntityType } from '@prisma/client';
|
||||
import { Scope, ScopeType } from '@/lib/types/scope';
|
||||
import { prismaClient } from '@/prisma';
|
||||
import prisma from '@/prisma';
|
||||
import { getUser } from '@/auth';
|
||||
import DashboardPageClient from '@/components/dashboardPageClientComponents';
|
||||
|
||||
|
@ -25,7 +25,7 @@ export default async function DashboardPage(props: { searchParams?: { scope: Sco
|
|||
const scope = Scope.of(props.searchParams?.scope || ScopeType.ThisMonth);
|
||||
|
||||
// get all payments in the current scope
|
||||
const payments = await prismaClient.payment.findMany({
|
||||
const payments = await prisma.payment.findMany({
|
||||
where: {
|
||||
userId: user?.id,
|
||||
date: {
|
||||
|
@ -108,6 +108,7 @@ export default async function DashboardPage(props: { searchParams?: { scope: Sco
|
|||
userId: '',
|
||||
name: 'Other',
|
||||
type: EntityType.Entity,
|
||||
defaultCategoryId: null,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { getUser } from '@/auth';
|
||||
import { prismaClient } from '@/prisma';
|
||||
import prisma from '@/prisma';
|
||||
import React from 'react';
|
||||
import PaymentPageClientContent from '@/components/paymentPageClientComponents';
|
||||
import paymentCreateUpdate from '@/lib/actions/paymentCreateUpdate';
|
||||
|
@ -9,7 +9,7 @@ export default async function PaymentsPage() {
|
|||
|
||||
const user = await getUser();
|
||||
|
||||
const payments = await prismaClient.payment.findMany({
|
||||
const payments = await prisma.payment.findMany({
|
||||
where: {
|
||||
userId: user?.id,
|
||||
},
|
||||
|
@ -23,7 +23,7 @@ export default async function PaymentsPage() {
|
|||
],
|
||||
});
|
||||
|
||||
const entities = await prismaClient.entity.findMany({
|
||||
const entities = await prisma.entity.findMany({
|
||||
where: {
|
||||
userId: user?.id,
|
||||
},
|
||||
|
@ -37,7 +37,7 @@ export default async function PaymentsPage() {
|
|||
],
|
||||
});
|
||||
|
||||
const categories = await prismaClient.category.findMany({
|
||||
const categories = await prisma.category.findMany({
|
||||
where: {
|
||||
userId: user?.id,
|
||||
},
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { Lucia } from 'lucia';
|
||||
import { PrismaAdapter } from '@lucia-auth/adapter-prisma';
|
||||
import { cookies } from 'next/headers';
|
||||
import { prismaClient } from '@/prisma';
|
||||
import prisma from '@/prisma';
|
||||
|
||||
const adapter = new PrismaAdapter(prismaClient.session, prismaClient.user);
|
||||
const adapter = new PrismaAdapter(prisma.session, prisma.user);
|
||||
|
||||
export const lucia = new Lucia(adapter, {
|
||||
sessionCookie: {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { ActionResponse } from '@/lib/types/actionResponse';
|
||||
import { URL_SIGN_IN } from '@/lib/constants';
|
||||
import { getUser, lucia } from '@/auth';
|
||||
import { prismaClient } from '@/prisma';
|
||||
import prisma from '@/prisma';
|
||||
import { cookies } from 'next/headers';
|
||||
|
||||
export default async function accountDelete(): Promise<ActionResponse> {
|
||||
|
@ -17,31 +17,31 @@ export default async function accountDelete(): Promise<ActionResponse> {
|
|||
};
|
||||
}
|
||||
|
||||
await prismaClient.payment.deleteMany({
|
||||
await prisma.payment.deleteMany({
|
||||
where: {
|
||||
userId: user.id,
|
||||
},
|
||||
});
|
||||
|
||||
await prismaClient.entity.deleteMany({
|
||||
await prisma.entity.deleteMany({
|
||||
where: {
|
||||
userId: user.id,
|
||||
},
|
||||
});
|
||||
|
||||
await prismaClient.category.deleteMany({
|
||||
await prisma.category.deleteMany({
|
||||
where: {
|
||||
userId: user.id,
|
||||
},
|
||||
});
|
||||
|
||||
await prismaClient.session.deleteMany({
|
||||
await prisma.session.deleteMany({
|
||||
where: {
|
||||
userId: user.id,
|
||||
},
|
||||
});
|
||||
|
||||
await prismaClient.user.delete({
|
||||
await prisma.user.delete({
|
||||
where: {
|
||||
id: user.id,
|
||||
},
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { z } from 'zod';
|
||||
import { ActionResponse } from '@/lib/types/actionResponse';
|
||||
import { prismaClient } from '@/prisma';
|
||||
import prisma from '@/prisma';
|
||||
import { getUser } from '@/auth';
|
||||
import { URL_SIGN_IN } from '@/lib/constants';
|
||||
import { categoryFormSchema } from '@/lib/form-schemas/categoryFormSchema';
|
||||
|
@ -25,7 +25,7 @@ export default async function categoryCreateUpdate({
|
|||
// create/update category
|
||||
try {
|
||||
if (id) {
|
||||
await prismaClient.category.update({
|
||||
await prisma.category.update({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
|
@ -42,7 +42,7 @@ export default async function categoryCreateUpdate({
|
|||
message: `'${name}' updated`,
|
||||
};
|
||||
} else {
|
||||
await prismaClient.category.create({
|
||||
await prisma.category.create({
|
||||
data: {
|
||||
userId: user.id,
|
||||
name: name,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { ActionResponse } from '@/lib/types/actionResponse';
|
||||
import { prismaClient } from '@/prisma';
|
||||
import prisma from '@/prisma';
|
||||
import { getUser } from '@/auth';
|
||||
import { URL_SIGN_IN } from '@/lib/constants';
|
||||
|
||||
|
@ -25,7 +25,7 @@ export default async function categoryDelete(id: number): Promise<ActionResponse
|
|||
}
|
||||
|
||||
// check that category is associated with user
|
||||
const category = await prismaClient.category.findFirst({
|
||||
const category = await prisma.category.findFirst({
|
||||
where: {
|
||||
id: id,
|
||||
userId: user.id,
|
||||
|
@ -40,7 +40,7 @@ export default async function categoryDelete(id: number): Promise<ActionResponse
|
|||
|
||||
// delete category
|
||||
try {
|
||||
await prismaClient.category.delete({
|
||||
await prisma.category.delete({
|
||||
where: {
|
||||
id: category.id,
|
||||
userId: user.id,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { z } from 'zod';
|
||||
import { ActionResponse } from '@/lib/types/actionResponse';
|
||||
import { entityFormSchema } from '@/lib/form-schemas/entityFormSchema';
|
||||
import { prismaClient } from '@/prisma';
|
||||
import prisma from '@/prisma';
|
||||
import { getUser } from '@/auth';
|
||||
import { URL_SIGN_IN } from '@/lib/constants';
|
||||
|
||||
|
@ -26,7 +26,7 @@ export default async function entityCreateUpdate({
|
|||
// create/update entity
|
||||
try {
|
||||
if (id) {
|
||||
await prismaClient.entity.update({
|
||||
await prisma.entity.update({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
|
@ -44,7 +44,7 @@ export default async function entityCreateUpdate({
|
|||
message: `${type} '${name}' updated`,
|
||||
};
|
||||
} else {
|
||||
await prismaClient.entity.create({
|
||||
await prisma.entity.create({
|
||||
data: {
|
||||
userId: user.id,
|
||||
name: name,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { ActionResponse } from '@/lib/types/actionResponse';
|
||||
import { prismaClient } from '@/prisma';
|
||||
import prisma from '@/prisma';
|
||||
import { getUser } from '@/auth';
|
||||
import { URL_SIGN_IN } from '@/lib/constants';
|
||||
|
||||
|
@ -25,7 +25,7 @@ export default async function entityDelete(id: number): Promise<ActionResponse>
|
|||
}
|
||||
|
||||
// check that entity is associated with user
|
||||
const entity = await prismaClient.entity.findFirst({
|
||||
const entity = await prisma.entity.findFirst({
|
||||
where: {
|
||||
id: id,
|
||||
userId: user.id,
|
||||
|
@ -40,7 +40,7 @@ export default async function entityDelete(id: number): Promise<ActionResponse>
|
|||
|
||||
// delete entity
|
||||
try {
|
||||
await prismaClient.entity.delete({
|
||||
await prisma.entity.delete({
|
||||
where: {
|
||||
id: entity.id,
|
||||
userId: user.id,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { prismaClient } from '@/prisma';
|
||||
import prisma from '@/prisma';
|
||||
import type { Category, Entity } from '@prisma/client';
|
||||
import { EntityType } from '@prisma/client';
|
||||
import { getUser } from '@/auth';
|
||||
|
@ -19,12 +19,12 @@ export default async function generateSampleData(): Promise<ActionResponse> {
|
|||
}
|
||||
|
||||
// Categories: create sample data
|
||||
const categories: Category[] = await prismaClient.category.findMany({where: {userId: user.id}});
|
||||
if (await prismaClient.category.count({where: {userId: user.id}}) == 0) {
|
||||
const categories: Category[] = await prisma.category.findMany({where: {userId: user.id}});
|
||||
if (await prisma.category.count({where: {userId: user.id}}) == 0) {
|
||||
|
||||
console.log('Creating sample categories...');
|
||||
|
||||
categories.push(await prismaClient.category.create({
|
||||
categories.push(await prisma.category.create({
|
||||
data: {
|
||||
userId: user.id,
|
||||
name: 'Groceries',
|
||||
|
@ -32,7 +32,7 @@ export default async function generateSampleData(): Promise<ActionResponse> {
|
|||
},
|
||||
}));
|
||||
|
||||
categories.push(await prismaClient.category.create({
|
||||
categories.push(await prisma.category.create({
|
||||
data: {
|
||||
userId: user.id,
|
||||
name: 'Drugstore items',
|
||||
|
@ -40,7 +40,7 @@ export default async function generateSampleData(): Promise<ActionResponse> {
|
|||
},
|
||||
}));
|
||||
|
||||
categories.push(await prismaClient.category.create({
|
||||
categories.push(await prisma.category.create({
|
||||
data: {
|
||||
userId: user.id,
|
||||
name: 'Going out',
|
||||
|
@ -48,7 +48,7 @@ export default async function generateSampleData(): Promise<ActionResponse> {
|
|||
},
|
||||
}));
|
||||
|
||||
categories.push(await prismaClient.category.create({
|
||||
categories.push(await prisma.category.create({
|
||||
data: {
|
||||
userId: user.id,
|
||||
name: 'Random stuff',
|
||||
|
@ -56,7 +56,7 @@ export default async function generateSampleData(): Promise<ActionResponse> {
|
|||
},
|
||||
}));
|
||||
|
||||
categories.push(await prismaClient.category.create({
|
||||
categories.push(await prisma.category.create({
|
||||
data: {
|
||||
userId: user.id,
|
||||
name: 'Salary',
|
||||
|
@ -69,12 +69,12 @@ export default async function generateSampleData(): Promise<ActionResponse> {
|
|||
console.log(categories);
|
||||
|
||||
// Entities: create sample data
|
||||
const entities: Entity[] = await prismaClient.entity.findMany({where: {userId: user.id}});
|
||||
if (await prismaClient.entity.count({where: {userId: user.id}}) == 0) {
|
||||
const entities: Entity[] = await prisma.entity.findMany({where: {userId: user.id}});
|
||||
if (await prisma.entity.count({where: {userId: user.id}}) == 0) {
|
||||
|
||||
console.log('Creating sample entities...');
|
||||
|
||||
entities.push(await prismaClient.entity.create({
|
||||
entities.push(await prisma.entity.create({
|
||||
data: {
|
||||
userId: user.id,
|
||||
name: 'Main Account',
|
||||
|
@ -82,7 +82,7 @@ export default async function generateSampleData(): Promise<ActionResponse> {
|
|||
},
|
||||
}));
|
||||
|
||||
entities.push(await prismaClient.entity.create({
|
||||
entities.push(await prisma.entity.create({
|
||||
data: {
|
||||
userId: user.id,
|
||||
name: 'Company',
|
||||
|
@ -90,7 +90,7 @@ export default async function generateSampleData(): Promise<ActionResponse> {
|
|||
},
|
||||
}));
|
||||
|
||||
entities.push(await prismaClient.entity.create({
|
||||
entities.push(await prisma.entity.create({
|
||||
data: {
|
||||
userId: user.id,
|
||||
name: 'Supermarket 1',
|
||||
|
@ -98,7 +98,7 @@ export default async function generateSampleData(): Promise<ActionResponse> {
|
|||
},
|
||||
}));
|
||||
|
||||
entities.push(await prismaClient.entity.create({
|
||||
entities.push(await prisma.entity.create({
|
||||
data: {
|
||||
userId: user.id,
|
||||
name: 'Supermarket 2',
|
||||
|
@ -106,7 +106,7 @@ export default async function generateSampleData(): Promise<ActionResponse> {
|
|||
},
|
||||
}));
|
||||
|
||||
entities.push(await prismaClient.entity.create({
|
||||
entities.push(await prisma.entity.create({
|
||||
data: {
|
||||
userId: user.id,
|
||||
name: 'Supermarket 3',
|
||||
|
@ -114,7 +114,7 @@ export default async function generateSampleData(): Promise<ActionResponse> {
|
|||
},
|
||||
}));
|
||||
|
||||
entities.push(await prismaClient.entity.create({
|
||||
entities.push(await prisma.entity.create({
|
||||
data: {
|
||||
userId: user.id,
|
||||
name: 'Supermarket 4',
|
||||
|
@ -129,14 +129,14 @@ export default async function generateSampleData(): Promise<ActionResponse> {
|
|||
// Payments: create sample data
|
||||
console.log('Creating sample payments...');
|
||||
|
||||
if (await prismaClient.payment.count({where: {userId: user.id}}) == 0) {
|
||||
if (await prisma.payment.count({where: {userId: user.id}}) == 0) {
|
||||
for (let i = 0; i < 4; i++) {
|
||||
|
||||
const date = new Date();
|
||||
date.setDate(1);
|
||||
date.setMonth(date.getMonth() - i);
|
||||
|
||||
await prismaClient.payment.create({
|
||||
await prisma.payment.create({
|
||||
data: {
|
||||
userId: user.id,
|
||||
amount: 200000,
|
||||
|
@ -164,7 +164,7 @@ export default async function generateSampleData(): Promise<ActionResponse> {
|
|||
const date = new Date(
|
||||
new Date().getTime() - Math.floor(Math.random() * 10000000000));
|
||||
|
||||
await prismaClient.payment.create({
|
||||
await prisma.payment.create({
|
||||
data: {
|
||||
userId: user.id,
|
||||
amount: Math.floor(
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { z } from 'zod';
|
||||
import { ActionResponse } from '@/lib/types/actionResponse';
|
||||
import { prismaClient } from '@/prisma';
|
||||
import prisma from '@/prisma';
|
||||
import { getUser } from '@/auth';
|
||||
import { URL_SIGN_IN } from '@/lib/constants';
|
||||
import { paymentFormSchema } from '@/lib/form-schemas/paymentFormSchema';
|
||||
|
@ -29,7 +29,7 @@ export default async function paymentCreateUpdate({
|
|||
// create/update payment
|
||||
try {
|
||||
if (id) {
|
||||
await prismaClient.payment.update({
|
||||
await prisma.payment.update({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
|
@ -50,7 +50,7 @@ export default async function paymentCreateUpdate({
|
|||
message: `Payment updated`,
|
||||
};
|
||||
} else {
|
||||
await prismaClient.payment.create({
|
||||
await prisma.payment.create({
|
||||
data: {
|
||||
userId: user.id,
|
||||
amount: amount,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { ActionResponse } from '@/lib/types/actionResponse';
|
||||
import { prismaClient } from '@/prisma';
|
||||
import prisma from '@/prisma';
|
||||
import { getUser } from '@/auth';
|
||||
import { URL_SIGN_IN } from '@/lib/constants';
|
||||
|
||||
|
@ -25,7 +25,7 @@ export default async function paymentDelete(id: number): Promise<ActionResponse>
|
|||
}
|
||||
|
||||
// check that payment is associated with user
|
||||
const payment = await prismaClient.payment.findFirst({
|
||||
const payment = await prisma.payment.findFirst({
|
||||
where: {
|
||||
id: id,
|
||||
userId: user.id,
|
||||
|
@ -40,7 +40,7 @@ export default async function paymentDelete(id: number): Promise<ActionResponse>
|
|||
|
||||
// delete payment
|
||||
try {
|
||||
await prismaClient.payment.delete({
|
||||
await prisma.payment.delete({
|
||||
where: {
|
||||
id: payment.id,
|
||||
userId: user.id,
|
||||
|
|
|
@ -5,12 +5,12 @@ import { cookies } from 'next/headers';
|
|||
import { signInFormSchema } from '@/lib/form-schemas/signInFormSchema';
|
||||
import { ActionResponse } from '@/lib/types/actionResponse';
|
||||
import { URL_HOME } from '@/lib/constants';
|
||||
import { prismaClient } from '@/prisma';
|
||||
import prisma from '@/prisma';
|
||||
|
||||
export default async function signIn({username, password}: z.infer<typeof signInFormSchema>): Promise<ActionResponse> {
|
||||
'use server';
|
||||
|
||||
const existingUser = await prismaClient.user.findFirst({
|
||||
const existingUser = await prisma.user.findFirst({
|
||||
where: {
|
||||
username: username.toLowerCase(),
|
||||
},
|
||||
|
|
|
@ -6,7 +6,7 @@ import { cookies } from 'next/headers';
|
|||
import { signUpFormSchema } from '@/lib/form-schemas/signUpFormSchema';
|
||||
import { ActionResponse } from '@/lib/types/actionResponse';
|
||||
import { URL_HOME } from '@/lib/constants';
|
||||
import { prismaClient } from '@/prisma';
|
||||
import prisma from '@/prisma';
|
||||
|
||||
export default async function signUp({username, password}: z.infer<typeof signUpFormSchema>): Promise<ActionResponse> {
|
||||
'use server';
|
||||
|
@ -14,7 +14,7 @@ export default async function signUp({username, password}: z.infer<typeof signUp
|
|||
const hashedPassword = await new Argon2id().hash(password);
|
||||
const userId = generateId(15);
|
||||
|
||||
const existingUser = await prismaClient.user.findFirst({
|
||||
const existingUser = await prisma.user.findFirst({
|
||||
where: {
|
||||
username: username.toLowerCase(),
|
||||
},
|
||||
|
@ -27,7 +27,7 @@ export default async function signUp({username, password}: z.infer<typeof signUp
|
|||
};
|
||||
}
|
||||
|
||||
await prismaClient.user.create({
|
||||
await prisma.user.create({
|
||||
data: {
|
||||
id: userId,
|
||||
username: username,
|
||||
|
|
|
@ -1,3 +1,18 @@
|
|||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
export const prismaClient = new PrismaClient();
|
||||
const prismaClientSingleton = () => {
|
||||
return new PrismaClient();
|
||||
};
|
||||
|
||||
declare global {
|
||||
// noinspection ES6ConvertVarToLetConst
|
||||
var prismaGlobal: undefined | ReturnType<typeof prismaClientSingleton>;
|
||||
}
|
||||
|
||||
const prisma = globalThis.prismaGlobal ?? prismaClientSingleton();
|
||||
|
||||
export default prisma;
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
globalThis.prismaGlobal = prisma
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue