Merge branch 'dev' into boards

# Conflicts:
#	.gitignore
#	package.json
#	pnpm-lock.yaml
#	prisma/migrations/16_boards/migration.sql
#	prisma/schema.prisma
#	src/app/(main)/MobileNav.tsx
#	src/app/(main)/websites/[websiteId]/WebsiteHeader.tsx
#	src/app/(main)/websites/[websiteId]/settings/WebsiteShareForm.tsx
#	src/components/common/SideMenu.tsx
#	src/lib/types.ts
This commit is contained in:
Mike Cao committed 2026-02-05 20:05:25 -08:00
commit c3e0290e65
150 files changed
+3028 -787

No files matched your search

+39 -2
View File
@@ -1,14 +1,15 @@
import type { Prisma } from '@/generated/prisma/client';
import prisma from '@/lib/prisma';
import type { QueryFilters } from '@/lib/types';
export async function findShare(criteria: Prisma.ShareFindUniqueArgs) {
return prisma.client.share.findUnique(criteria);
}
export async function getShare(entityId: string) {
export async function getShare(shareId: string) {
return findShare({
where: {
id: entityId,
id: shareId,
},
});
}
@@ -21,6 +22,34 @@ export async function getShareByCode(slug: string) {
});
}
export async function getShareByEntityId(entityId: string) {
return prisma.client.share.findFirst({
where: {
entityId,
},
orderBy: {
createdAt: 'desc',
},
});
}
export async function getSharesByEntityId(entityId: string, filters?: QueryFilters) {
const { pagedQuery } = prisma;
return pagedQuery(
'share',
{
where: {
entityId,
},
orderBy: {
createdAt: 'desc',
},
},
filters,
);
}
export async function createShare(
data: Prisma.ShareCreateInput | Prisma.ShareUncheckedCreateInput,
) {
@@ -44,3 +73,11 @@ export async function updateShare(
export async function deleteShare(shareId: string) {
return prisma.client.share.delete({ where: { id: shareId } });
}
export async function deleteSharesByEntityId(entityId: string) {
return prisma.client.share.deleteMany({
where: {
entityId,
},
});
}
+1 -1
View File
@@ -18,7 +18,7 @@ async function findUser(criteria: Prisma.UserFindUniqueArgs, options: GetUserOpt
...criteria,
where: {
...criteria.where,
...(showDeleted && { deletedAt: null }),
...(showDeleted ? {} : { deletedAt: null }),
},
select: {
id: true,
+72 -3
View File
@@ -1,4 +1,4 @@
import type { Prisma } from '@/generated/prisma/client';
import type { Prisma, Website } from '@/generated/prisma/client';
import { ROLES } from '@/lib/constants';
import prisma from '@/lib/prisma';
import redis from '@/lib/redis';
@@ -9,11 +9,17 @@ export async function findWebsite(criteria: Prisma.WebsiteFindUniqueArgs) {
}
export async function getWebsite(websiteId: string) {
return findWebsite({
const website = await findWebsite({
where: {
id: websiteId,
},
});
if (!website) {
return null;
}
return attachShareIdToWebsite(website);
}
export async function getWebsites(criteria: Prisma.WebsiteFindManyArgs, filters: QueryFilters) {
@@ -31,7 +37,9 @@ export async function getWebsites(criteria: Prisma.WebsiteFindManyArgs, filters:
deletedAt: null,
};
return pagedQuery('website', { ...criteria, where }, filters);
const websites = await pagedQuery('website', { ...criteria, where }, filters);
return attachShareIdToWebsites(websites);
}
export async function getAllUserWebsitesIncludingTeamOwner(userId: string, filters?: QueryFilters) {
@@ -203,6 +211,10 @@ export async function deleteWebsite(websiteId: string) {
where: { websiteId },
});
await tx.share.deleteMany({
where: { entityId: websiteId },
});
const website = cloudMode
? await tx.website.update({
data: {
@@ -236,3 +248,60 @@ export async function getWebsiteCount(userId: string) {
},
});
}
export async function attachShareIdToWebsite(website: Website) {
const share = await prisma.client.share.findFirst({
where: {
entityId: website.id,
},
orderBy: {
createdAt: 'desc',
},
select: {
slug: true,
},
});
return {
...website,
shareId: share?.slug ?? null,
};
}
export async function attachShareIdToWebsites(websites: {
data: any;
count: any;
page: number;
pageSize: number;
orderBy: string;
search: string;
}) {
const websiteIds = websites.data.map(website => website.id);
if (websiteIds.length === 0) {
return {
...websites,
data: websites.data.map(website => ({ ...website, shareId: null })),
};
}
const shares = await prisma.client.share.findMany({
where: {
entityId: { in: websiteIds },
},
distinct: ['entityId'],
orderBy: {
createdAt: 'desc',
},
});
const shareByWebsiteId = new Map(shares.map(share => [share.entityId, share.slug]));
return {
...websites,
data: websites.data.map(website => ({
...website,
shareId: shareByWebsiteId.get(website.id) ?? null,
})),
};
}