1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

release 0.3.4

This commit is contained in:
songjunxi
2023-11-10 14:59:47 +08:00
parent 2b456637e9
commit 602f2059fd
161 changed files with 9921 additions and 347 deletions

View File

@@ -0,0 +1,140 @@
import { ContentItem } from "../types/note";
import prisma from "./prisma";
export async function createCollaboration(
userId: string,
localId: string,
roomId: string,
title: string,
) {
return await prisma.collaboration.create({
data: {
userId,
localId,
roomId,
title,
click: 0,
createdAt: new Date(),
updatedAt: new Date(),
deletedAt: null,
expired: null,
},
});
}
export async function findCollaborationByRoomId(roomId: string, uid?: string) {
if (uid) {
return await prisma.collaboration.findFirst({
where: {
roomId,
userId: uid,
deletedAt: null,
expired: null,
},
});
} else {
return await prisma.collaboration.findFirst({
where: {
roomId,
// deletedAt: null,
// expired: null,
},
});
}
}
export async function findFirstCollaborationByRoomId(roomId: string) {
return await prisma.collaboration.findFirst({
where: {
roomId,
deletedAt: null,
expired: null,
},
// select: {
// userId: true,
// roomId: true,
// title: true,
// createdAt: true
// }
});
}
// 用户当前本地笔记是否已加入协作
export async function findCollaborationBylocalId(
localId: string,
userId: string,
) {
return await prisma.collaboration.findFirst({
where: {
userId,
localId,
deletedAt: null,
expired: null,
},
select: {
roomId: true,
},
});
}
// 邀请中转页调用
export async function findCollaborationByDBId(id: string) {
return await prisma.collaboration.findFirst({
where: {
id,
deletedAt: null,
expired: null,
},
});
}
// 该协作加入人数
export async function findCollaborationInviteCount(id: string) {
return await prisma.collaboration.count({
where: {
roomId: id,
deletedAt: null,
expired: null,
},
});
}
// 用户所有参与的协作分享
export async function findUserCollaborations(userId: string) {
return await prisma.collaboration.findMany({
where: {
userId,
deletedAt: null,
},
});
}
// export async function updateCollaboration(click: number, id: string) {
// return await prisma.collaboration.update({
// where: {
// id,
// },
// data: {
// click,
// updatedAt: new Date(),
// },
// });
// }
export async function updateCollaborationClick(id: string, pre: number) {
return await prisma.collaboration.update({
where: {
id,
},
data: {
click: pre + 1,
},
});
}
export async function deleteCollaborationNote(id: string) {
return await prisma.collaboration.update({
where: {
id,
},
data: {
deletedAt: new Date(),
},
});
}

11
apps/web/lib/db/prisma.ts Normal file
View File

@@ -0,0 +1,11 @@
import { PrismaClient } from "@prisma/client";
declare global {
var prisma: PrismaClient | undefined;
}
const prisma = global.prisma || new PrismaClient();
if (process.env.NODE_ENV === "development") global.prisma = prisma;
export default prisma;

103
apps/web/lib/db/share.ts Normal file
View File

@@ -0,0 +1,103 @@
import { ContentItem } from "../types/note";
import prisma from "./prisma";
export async function createShareNote(json: ContentItem, uid: string) {
return await prisma.shareNote.create({
data: {
userId: uid,
localId: json.id,
data: JSON.stringify(json),
click: 0,
keeps: 0,
createdAt: new Date(),
updatedAt: new Date(),
deletedAt: null,
},
});
}
export async function findShareByLocalId(id: string, uid?: string) {
if (uid) {
return await prisma.shareNote.findFirst({
where: {
localId: id,
userId: uid,
deletedAt: null,
},
});
} else {
return await prisma.shareNote.findFirst({
where: {
localId: id,
deletedAt: null,
},
});
}
}
export async function findShareByDBId(id: string) {
return await prisma.shareNote.findFirst({
where: {
id,
deletedAt: null,
},
});
}
export async function findUserSharesCount(uid: string) {
return await prisma.shareNote.count({
where: {
userId: uid,
deletedAt: null,
},
});
}
export async function findUserShares(uid: string) {
return await prisma.shareNote.findMany({
where: {
userId: uid,
deletedAt: null,
},
});
}
export async function updateShareNote(json: ContentItem, id: string) {
return await prisma.shareNote.update({
where: {
id,
},
data: {
data: JSON.stringify(json),
updatedAt: new Date(),
},
});
}
export async function updateShareClick(id: string, pre: number) {
return await prisma.shareNote.update({
where: {
id,
},
data: {
click: pre + 1,
},
});
}
export async function updateShareKeeps(id: string, pre: number) {
return await prisma.shareNote.update({
where: {
id,
},
data: {
keeps: pre + 1,
},
});
}
export async function deleteShareNote(id: string) {
return await prisma.shareNote.update({
where: {
id,
},
data: {
deletedAt: new Date(),
},
});
}

23
apps/web/lib/db/user.ts Normal file
View File

@@ -0,0 +1,23 @@
import prisma from "./prisma";
// get all users from user schema
export const getUsers = async () => {
return await prisma.user.findMany();
};
export const getUserByEmail = async (email: string) => {
return await prisma.user.findFirst({
where: { email },
});
};
export const getUserById = async (id: string) => {
return await prisma.user.findFirst({
where: { id },
select: { name: true, image: true },
});
};
export const updateUserName = async (id: string, name: string) => {
return await prisma.user.update({ data: { name }, where: { id } });
};