change database table name organization to house

This commit is contained in:
2026-02-24 10:36:53 +07:00
parent 604fe0a80f
commit 1e6f4683ea
17 changed files with 1822 additions and 1786 deletions

View File

@@ -1,5 +1,5 @@
import { prisma } from '@/db';
import { OrganizationWhereInput } from '@/generated/prisma/models';
import { HouseWhereInput } from '@/generated/prisma/models';
import { DB_TABLE, LOG_ACTION, NOTIFICATION_TYPE } from '@/types/enum';
import { auth } from '@lib/auth';
import { parseError } from '@lib/errors';
@@ -25,7 +25,7 @@ export const getAllHouse = createServerFn({ method: 'GET' })
const { page, limit, keyword } = data;
const skip = (page - 1) * limit;
const where: OrganizationWhereInput = {
const where: HouseWhereInput = {
OR: [
{
name: {
@@ -37,7 +37,7 @@ export const getAllHouse = createServerFn({ method: 'GET' })
};
const [list, total]: [HouseWithMembers[], number] = await Promise.all([
await prisma.organization.findMany({
await prisma.house.findMany({
where,
orderBy: { createdAt: 'desc' },
include: {
@@ -58,7 +58,7 @@ export const getAllHouse = createServerFn({ method: 'GET' })
take: limit,
skip,
}),
await prisma.organization.count({ where }),
await prisma.house.count({ where }),
]);
const totalPage = Math.ceil(+total / limit);
@@ -82,7 +82,7 @@ export const getCurrentUserHouses = createServerFn({ method: 'GET' })
.middleware([authMiddleware])
.handler(async ({ context: { user } }) => {
try {
const houses = await prisma.organization.findMany({
const houses = await prisma.house.findMany({
where: { members: { some: { userId: user.id } } },
orderBy: { createdAt: 'asc' },
include: {
@@ -148,13 +148,13 @@ export const updateHouse = createServerFn({ method: 'POST' })
.inputValidator(houseEditBESchema)
.handler(async ({ data, context: { user } }) => {
try {
const currentHouse = await prisma.organization.findUnique({
const currentHouse = await prisma.house.findUnique({
where: { id: data.id },
});
if (!currentHouse) throw Error('House not found');
const { id, slug, name, color } = data;
const result = await prisma.organization.update({
const result = await prisma.house.update({
where: { id },
data: {
name,
@@ -185,13 +185,13 @@ export const deleteHouse = createServerFn({ method: 'POST' })
.inputValidator(baseHouse)
.handler(async ({ data, context: { user } }) => {
try {
const currentHouse = await prisma.organization.findUnique({
const currentHouse = await prisma.house.findUnique({
where: { id: data.id },
});
if (!currentHouse) throw Error('House not found');
const result = await Promise.all([
prisma.organization.delete({
prisma.house.delete({
where: { id: data.id },
}),
prisma.member.deleteMany({
@@ -224,7 +224,7 @@ export const deleteUserHouse = createServerFn({ method: 'POST' })
.inputValidator(baseHouse)
.handler(async ({ data, context: { user } }) => {
try {
const currentHouse = await prisma.organization.findUnique({
const currentHouse = await prisma.house.findUnique({
where: { id: data.id },
});
if (!currentHouse) throw Error('House not found');
@@ -271,7 +271,7 @@ export const invitationMember = createServerFn({ method: 'POST' })
const cuser = await prisma.user.findUnique({
where: { email: data.email },
});
const chouse = await prisma.organization.findUnique({
const chouse = await prisma.house.findUnique({
where: { id: data.houseId },
});