mirror of
https://github.com/ahmadk953/tasko.git
synced 2025-05-04 04:33:10 +00:00
Initial Commit
This commit is contained in:
commit
f3e2f01bd7
150 changed files with 13612 additions and 0 deletions
37
lib/create-audit-log.ts
Normal file
37
lib/create-audit-log.ts
Normal file
|
@ -0,0 +1,37 @@
|
|||
import { auth, currentUser } from "@clerk/nextjs";
|
||||
import { ACTION, ENTITY_TYPE } from "@prisma/client";
|
||||
|
||||
import { db } from "@/lib/db";
|
||||
|
||||
interface Props {
|
||||
entityId: string;
|
||||
entityType: ENTITY_TYPE;
|
||||
entityTitle: string;
|
||||
action: ACTION;
|
||||
}
|
||||
|
||||
export const createAuditLog = async (props: Props) => {
|
||||
try {
|
||||
const { orgId } = auth();
|
||||
const user = await currentUser();
|
||||
|
||||
if (!orgId || !user) throw new Error("User not found");
|
||||
|
||||
const { entityId, entityType, entityTitle, action } = props;
|
||||
|
||||
await db.auditLog.create({
|
||||
data: {
|
||||
orgId,
|
||||
entityId,
|
||||
entityType,
|
||||
entityTitle,
|
||||
action,
|
||||
userId: user.id,
|
||||
userImage: user?.imageUrl,
|
||||
userName: user?.firstName + " " + user?.lastName,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("[AUDIT_LOG_ERROR]", error);
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue