diff --git a/app/(user)/team/page.tsx b/app/(user)/team/page.tsx index 39c048c..3dd31fe 100644 --- a/app/(user)/team/page.tsx +++ b/app/(user)/team/page.tsx @@ -1,25 +1,35 @@ -import fs from "fs"; -import path from "path"; +"use client"; + import CardName from "@/components/CardName"; import Head from "next/head"; +import { Userssss } from "@/app/admin/dashboard/manage-user/lib/definition"; +import { useState, useEffect } from "react"; -export interface CoreTeamMember { - nim: string; - name: string; - role: string; - picture: string; - profile_url: string; -} +export default function Team() { + const [users, setUsers] = useState([]); -export interface CoreTeam { - coreteam: CoreTeamMember[]; -} + useEffect(() => { + const fetchUsers = async () => { + try { + const response = await fetch('/api/user'); + if (response.ok) { + const data: Userssss[] = await response.json(); + setUsers(data); + } else { + console.error("Failed to fetch users."); + } + } catch (error) { + console.error("Error fetching users:", error); + } + }; + fetchUsers(); + }, []); -export default async function Team() { - // Read JSON data - const filePath = path.join(process.cwd(), "data", "coreteam.json"); - const fileContent = fs.readFileSync(filePath, "utf-8"); - const { coreteam } = JSON.parse(fileContent); + // Urutkan anggota tim berdasarkan role_tim + const rolePriority = ["LEAD", "COM_ADV", "AFM", "CORETIM"]; + const prioritizedUsers = users.filter(user => rolePriority.includes(user.role_tim)) + .sort((a, b) => rolePriority.indexOf(a.role_tim) - rolePriority.indexOf(b.role_tim)); + const memberUsers = users.filter(user => user.role_tim === "MEMBER"); return (
@@ -32,15 +42,39 @@ export default async function Team() { Ini adalah tim kami
- {coreteam.map((member: CoreTeamMember) => ( - - ))} + {/* Tampilkan anggota prioritas */} + {prioritizedUsers.length === 0 ? ( +

No team members found.

+ ) : ( + prioritizedUsers.map((user) => ( + + )) + )} +
+

+ Member +

+
+ {/* Tampilkan anggota member */} + {memberUsers.length === 0 ? ( +

No members found.

+ ) : ( + memberUsers.map((user) => ( + + )) + )}
diff --git a/app/admin/dashboard/manage-user/[email]/edit/page.tsx b/app/admin/dashboard/manage-user/[email]/edit/page.tsx new file mode 100644 index 0000000..f5509b3 --- /dev/null +++ b/app/admin/dashboard/manage-user/[email]/edit/page.tsx @@ -0,0 +1,54 @@ +"use client"; + +import React, { FC } from "react"; +import { notFound } from "next/navigation"; +import UserForm from "../../components/userForm"; +import { Userssss } from "../../lib/definition"; + +interface EditUserPageProps { + params: Promise<{ email: string }>; // `params` adalah Promise +} + +const EditUserPage: FC = ({ params }) => { + const { email } = React.use(params); // Unwrap `params` menggunakan `React.use()` + + const [user, setUser] = React.useState(null); + const [loading, setLoading] = React.useState(true); + + React.useEffect(() => { + const fetchUser = async () => { + try { + const res = await fetch(`/api/user/${email}`); + if (!res.ok) { + throw new Error("User not found"); + } + const userData: Userssss = await res.json(); + setUser(userData); + } catch (error) { + console.error("Error fetching user:", error); + setUser(null); + } finally { + setLoading(false); + } + }; + + fetchUser(); + }, [email]); + + if (loading) { + return
Loading...
; + } + + if (!user) { + return
User not found
; + } + + return ( +
+

Edit User

+ +
+ ); +}; + +export default EditUserPage; diff --git a/app/admin/dashboard/manage-user/[id]/edit/page.tsx b/app/admin/dashboard/manage-user/[id]/edit/page.tsx deleted file mode 100644 index 719d5cf..0000000 --- a/app/admin/dashboard/manage-user/[id]/edit/page.tsx +++ /dev/null @@ -1,62 +0,0 @@ -"use client"; - -import React, { FC, useEffect, useState } from 'react'; -import { USERS } from '../../data/users'; -import { notFound } from 'next/navigation'; -import UserForm from '../../components/userForm'; - -// Assuming the User and UserRole types are defined as shown above -import { User, UserRole } from '../../lib/definition'; - -interface EditUserPageProps { - params: Promise<{ id: string }>; -} - -const EditUserPage: FC = ({ params }) => { - const [user, setUser] = useState(null); - const [loading, setLoading] = useState(true); - const [id, setId] = useState(null); - - useEffect(() => { - const fetchParams = async () => { - const resolvedParams = await params; - setId(resolvedParams.id); - }; - - fetchParams(); - }, [params]); - - useEffect(() => { - if (id) { - const existingUser = USERS.find((user) => user.id === id); - if (!existingUser) { - notFound(); - } else { - // Ensure the role is set correctly - const updatedUser: User = { - ...existingUser, - role: existingUser.role as UserRole, // Cast if necessary, or ensure role is a valid UserRole - }; - setUser(updatedUser); - } - setLoading(false); - } - }, [id]); - - if (loading) { - return
Loading...
; - } - - if (!user) { - return
User not found
; - } - - return ( -
-

Edit User

- -
- ); -} - -export default EditUserPage; diff --git a/app/admin/dashboard/manage-user/components/actionButton.tsx b/app/admin/dashboard/manage-user/components/actionButton.tsx index d3613a4..44105db 100644 --- a/app/admin/dashboard/manage-user/components/actionButton.tsx +++ b/app/admin/dashboard/manage-user/components/actionButton.tsx @@ -22,29 +22,46 @@ import { import { Button } from '@/components/ui/button'; import { DialogClose } from '@radix-ui/react-dialog'; -import { User } from '../lib/definition'; +import { Userssss } from '../lib/definition'; +import toast from 'react-hot-toast'; interface ActionButtonProps { - data: User, + data: Userssss, type: "USER"; } const ActionButton: FC = ({ data }) => { const router = useRouter(); + const [isDeleteConfirmed, setIsDeleteConfirmed] = React.useState(false); const handleSeeDetailClick = () => { - if (data.profile_url) { - router.push(data.profile_url); + console.log(data.profil_bevy); + if (data.profil_bevy) { + router.push(data.profil_bevy); } } const handleEditClick = () => { - const url = `manage-user/${data.id}/edit`; // Changed to const + const url = `manage-user/${data.email}/edit`; // Changed to const router.push(url); } - const handleDeleteClick = () => { - // Pass + const handleDeleteClick = async () => { + const res = await fetch(`/api/user/${data.email}`, { + method: 'DELETE', + }); + + if (res.ok) { + toast.success('User deleted successfully'); + router.refresh(); + router.push('/admin/dashboard'); + }else{ + toast.error('Failed to delete user'); + } + } + + const handleDilogOpen = () => { + setIsDeleteConfirmed(true); } return ( @@ -75,7 +92,7 @@ const ActionButton: FC = ({ data }) => { - @@ -99,7 +116,9 @@ const ActionButton: FC = ({ data }) => { - + diff --git a/app/admin/dashboard/manage-user/components/userColumns.tsx b/app/admin/dashboard/manage-user/components/userColumns.tsx index 8f0bb03..488516e 100644 --- a/app/admin/dashboard/manage-user/components/userColumns.tsx +++ b/app/admin/dashboard/manage-user/components/userColumns.tsx @@ -2,10 +2,10 @@ import { ColumnDef } from "@tanstack/react-table" import ActionButton from "./actionButton" -import { User } from "../lib/definition" +import { Userssss } from "../lib/definition"; import Image from 'next/image' // Import Image from next/image -export const columns: ColumnDef[] = [ +export const columns: ColumnDef[] = [ { id: "count", header: "#", @@ -20,7 +20,7 @@ export const columns: ColumnDef[] = [ const user = row.original; return
user[] = [
} }, + { + accessorKey: "role-tim", + header: "Role Tim", + cell: ({ row }) => { + const user = row.original; + return
+ {user.role_tim} +
+ } + }, { id: "action", header: () => { diff --git a/app/admin/dashboard/manage-user/components/userForm.tsx b/app/admin/dashboard/manage-user/components/userForm.tsx index 5365e01..5f4cd99 100644 --- a/app/admin/dashboard/manage-user/components/userForm.tsx +++ b/app/admin/dashboard/manage-user/components/userForm.tsx @@ -1,62 +1,219 @@ "use client"; -import React, { FC } from 'react' -import { User, UserRole } from '../lib/definition' -import { Label } from '@/components/ui/label' -import { Input } from '@/components/ui/input' - -import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' -import { Button } from '@/components/ui/button' -import { useRouter } from 'next/navigation' +import React, { FC, useState } from "react"; +import { Userssss, UserRole, TimRole } from "../lib/definition"; +import { Label } from "@/components/ui/label"; +import { Input } from "@/components/ui/input"; +import { + Select, + SelectContent, + SelectGroup, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select"; +import { Button } from "@/components/ui/button"; +import { useRouter } from "next/navigation"; +import toast from "react-hot-toast"; interface UserFormProps { - user?: User, - type: "ADD" | "EDIT" + user?: Userssss; + type: "ADD" | "EDIT"; } const UserForm: FC = ({ user, type }) => { - const router = useRouter(); - - const userRoles = Object.values(UserRole); - - return ( - <> -
- {/* add for profile picture */} -
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - ) -} + const router = useRouter(); + const userRoles = Object.values(UserRole); + const timRoles = Object.values(TimRole); + const [updatePassword, setUpdatePassword] = useState(false); + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + + const formData = new FormData(e.currentTarget); + const data = Object.fromEntries(formData.entries()); + if (!updatePassword) { + delete data.password; // Hapus password jika user memilih tidak mengupdate password + } + const method = type === "EDIT" ? "PUT" : "POST"; + const url = type === "EDIT" ? `/api/user/${user?.email}` : "/api/user"; + + try { + const response = await fetch(url, { + method, + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(data), + }); + + if (response.ok) { + toast.success("User updated successfully"); + router.push("/admin/dashboard/manage-user"); + } else { + const error = await response.json(); + toast.error(error.error || "Something went wrong"); + } + } catch (error) { + toast.error("An error occurred while submitting the form"); + } + }; + return ( + <> +
+
+ +
+ as listed on bevy + +
+
+ +
+ +
+
+ +
+ as listed on bevy + +
+ {type === "EDIT" && ( +
+ +
+ )} + {updatePassword && ( +
+ + +
+ )} +
+ +
+ use link for bevy + +
+
+ +
+ use link cdn only + +
+
+ + +
+
+ + +
+
+ + +
+
+ + ); +}; -export default UserForm \ No newline at end of file +export default UserForm; diff --git a/app/admin/dashboard/manage-user/data/users.ts b/app/admin/dashboard/manage-user/data/users.ts index f7a4b9a..ab19635 100644 --- a/app/admin/dashboard/manage-user/data/users.ts +++ b/app/admin/dashboard/manage-user/data/users.ts @@ -1,35 +1,35 @@ -import {User, UserRole} from "../lib/definition"; +// import {User, UserRole} from "../lib/definition"; -const USERS: User[] = [ - { - id: "1", - name: "Refiana", - email: "reviana@gmail.com", - picture: "https://res.cloudinary.com/startup-grind/image/upload/c_fill,w_250,h_250,g_center/c_fill,dpr_2.0,f_auto,g_center,q_auto:good/v1/gcs/platform-data-goog/avatars/refiana_andiyah_UQKxPph.jpg", - role: UserRole.ADMIN, - profile_url: "https://gdg.community.dev/u/refiana/", - }, +// const USERS: User[] = [ +// { +// id: "1", +// name: "Refiana", +// email: "reviana@gmail.com", +// picture: "https://res.cloudinary.com/startup-grind/image/upload/c_fill,w_250,h_250,g_center/c_fill,dpr_2.0,f_auto,g_center,q_auto:good/v1/gcs/platform-data-goog/avatars/refiana_andiyah_UQKxPph.jpg", +// role: UserRole.ADMIN, +// profile_url: "https://gdg.community.dev/u/refiana/", +// }, - { - id: "2", - name: "Alvian Rahmadani Saputra", - email: "alvian@gmail.com", - picture: "https://res.cloudinary.com/startup-grind/image/upload/c_fill,w_250,h_250,g_center/c_fill,dpr_2.0,f_auto,g_center,q_auto:good/v1/gcs/platform-data-goog/avatars/alvian_rahmadani_ikZ8sYg.jpg", - role: UserRole.USER, - profile_url: "https://gdg.community.dev/u/myfmmz/", - }, +// { +// id: "2", +// name: "Alvian Rahmadani Saputra", +// email: "alvian@gmail.com", +// picture: "https://res.cloudinary.com/startup-grind/image/upload/c_fill,w_250,h_250,g_center/c_fill,dpr_2.0,f_auto,g_center,q_auto:good/v1/gcs/platform-data-goog/avatars/alvian_rahmadani_ikZ8sYg.jpg", +// role: UserRole.USER, +// profile_url: "https://gdg.community.dev/u/myfmmz/", +// }, - { - id: "3", - name: "Dimas Ardiminda Edia Putra", - email: "dimas@gmail.com", - picture: "https://res.cloudinary.com/startup-grind/image/upload/c_fill,w_250,h_250,g_center/c_fill,dpr_2.0,f_auto,g_center,q_auto:good/v1/gcs/platform-data-goog/avatars/dimas_ardiminda_edia_putra_BOEQ0iu.jpg", - role: UserRole.USER, - profile_url: "https://gdg.community.dev/u/a_dimas_ardiminda/", - }, -] +// { +// id: "3", +// name: "Dimas Ardiminda Edia Putra", +// email: "dimas@gmail.com", +// picture: "https://res.cloudinary.com/startup-grind/image/upload/c_fill,w_250,h_250,g_center/c_fill,dpr_2.0,f_auto,g_center,q_auto:good/v1/gcs/platform-data-goog/avatars/dimas_ardiminda_edia_putra_BOEQ0iu.jpg", +// role: UserRole.USER, +// profile_url: "https://gdg.community.dev/u/a_dimas_ardiminda/", +// }, +// ] -export { USERS }; +// export { USERS }; diff --git a/app/admin/dashboard/manage-user/lib/definition.tsx b/app/admin/dashboard/manage-user/lib/definition.tsx index 58dd961..2fb7ca8 100644 --- a/app/admin/dashboard/manage-user/lib/definition.tsx +++ b/app/admin/dashboard/manage-user/lib/definition.tsx @@ -1,15 +1,28 @@ export enum UserRole { - ADMIN = "Admin", - USER = "User" + ADMIN = "ADMIN", + MEMBER = "MEMBER", + SUPERADMIN = "SUPERADMIN" } +export enum TimRole { + CORETIM = "CORETIM", + LEAD = "LEAD", + AFM = "AFM", + COM_ADV = "COM_ADV", + MEMBER = "MEMBER" +} -export interface User { - id: string, - name: string, - email: string, - picture: string, - role: UserRole, - profile_url: string, -} \ No newline at end of file +export interface Userssss { + id: string; + nim: string; + name: string; + email: string; + role: UserRole; + avatar: string; + profil_bevy: string; + createdAt: Date; + role_tim: string; + password: string; + updatedAt: Date; +} diff --git a/app/admin/dashboard/manage-user/page.tsx b/app/admin/dashboard/manage-user/page.tsx index 3cbcd3d..38417cc 100644 --- a/app/admin/dashboard/manage-user/page.tsx +++ b/app/admin/dashboard/manage-user/page.tsx @@ -1,32 +1,79 @@ -"use client" +"use client"; import { Button } from "@/components/ui/button"; import { useRouter } from "next/navigation"; -import { FC } from "react"; +import { FC, useState, useEffect } from "react"; import { DataTable } from "@/components/ui/data-table"; import { Input } from "@/components/ui/input"; import { columns } from "./components/userColumns"; -import { USERS } from "./data/users"; - +import { Userssss } from "./lib/definition"; const UserPage: FC = () => { - const router = useRouter(); - - return ( -
-
-

User

-
- -
- -
-
-
- - + const router = useRouter(); + const [users, setUsers] = useState([]); + const [filteredUsers, setFilteredUsers] = useState([]); + const [searchTerm, setSearchTerm] = useState(""); + const [loading, setLoading] = useState(true); + + useEffect(() => { + const fetchUsers = async () => { + try { + const response = await fetch('/api/user'); + if (response.ok) { + const data: Userssss[] = await response.json(); + setUsers(data); + setFilteredUsers(data); // Initialize filteredUsers with the full list + } else { + console.error("Failed to fetch users."); + } + } catch (error) { + console.error("Error fetching users:", error); + } finally { + setLoading(false); + } + }; + + fetchUsers(); + }, []); + + // Handle search term updates + useEffect(() => { + const results = users.filter((user) => + user.name.toLowerCase().includes(searchTerm.toLowerCase()) || + user.role_tim.toLowerCase().includes(searchTerm.toLowerCase()) || + user.nim.toLowerCase().includes(searchTerm.toLowerCase()) + ); + setFilteredUsers(results); + }, [searchTerm, users]); + + if (loading) { + return

Loading users...

; + } + + return ( +
+
+

User

+
+ +
+ setSearchTerm(e.target.value)} + /> +
- ) -} +
+ + +
+ ); +}; -export default UserPage; \ No newline at end of file +export default UserPage; diff --git a/app/api/user/[email]/route.tsx b/app/api/user/[email]/route.tsx new file mode 100644 index 0000000..f598c50 --- /dev/null +++ b/app/api/user/[email]/route.tsx @@ -0,0 +1,79 @@ +import { NextResponse, NextRequest } from "next/server"; +import { prisma } from "@/lib/prisma"; +import { hash } from "bcrypt"; + + +// delete user +export async function DELETE(req: Request, { params }: { params: Promise<{ email: string }> }) { + const { email } = await params; + + try { + const deletedUser = await prisma.user.delete({ + where: { email }, + }); + return NextResponse.json(deletedUser); + } catch (error) { + console.error("Error deleting user:", error); + return NextResponse.json({ error: 'User delete failed', details: (error as Error).message }, { status: 400 }); + } +} + + +// GET user by email +export async function GET(req: NextRequest, { params }: { params: Promise<{ email: string }> }) { + const { email } = await params; + + if (!email || typeof email !== "string") { + return NextResponse.json({ error: "Invalid email" }, { status: 400 }); + } + + try { + const user = await prisma.user.findUnique({ + where: { email }, + }); + + if (!user) { + return NextResponse.json({ error: "User not found" }, { status: 404 }); + } + + return NextResponse.json(user); + } catch (error) { + console.error("Error fetching user:", error); + return NextResponse.json( + { error: "Failed to fetch user", details: (error as Error).message }, + { status: 500 } + ); + } + } + +// PUT update user +export async function PUT(req: NextRequest, { params }: { params: Promise<{ email: string }> }) { + const { email } = await params; + const body = await req.json(); + const { name, password, role, nim, avatar, profil_bevy, role_tim } = body; + + if (!email || typeof email !== "string") { + return NextResponse.json({ error: "Invalid email" }, { status: 400 }); + } + + try { + const dataToUpdate: any = { name, role, nim, avatar, profil_bevy, role_tim }; + + if (password) { + dataToUpdate.password = await hash(password, 10); // Hash password sebelum menyimpan + } + + const updatedUser = await prisma.user.update({ + where: { email }, + data: dataToUpdate, + }); + + return NextResponse.json(updatedUser); + } catch (error) { + console.error("Error updating user:", error); + return NextResponse.json( + { error: "Failed to update user", details: (error as Error).message }, + { status: 500 } + ); + } +} \ No newline at end of file diff --git a/app/api/user/route.tsx b/app/api/user/route.tsx new file mode 100644 index 0000000..fa3de99 --- /dev/null +++ b/app/api/user/route.tsx @@ -0,0 +1,39 @@ +import { NextResponse } from 'next/server'; +import { prisma } from '@/lib/prisma'; +import bcrypt from 'bcrypt'; + +export async function GET() { + try { + const users = await prisma.user.findMany(); + return NextResponse.json(users); + } catch (error) { + console.error('Error fetching users:', error); + return NextResponse.json({ error: 'Failed to fetch users' }, { status: 500 }); + } +} + + +export async function POST(req: Request) { + const { name, email, password, role, nim, avatar, profil_bevy, role_tim } = await req.json(); + const passwordHash = await bcrypt.hash(password, 10); + // console.log("data : ", name, email, password, role, nim, avatar, profil_bevy, role_tim); + try { + const newMember = await prisma.user.create({ + data: { + name, + email, + password: passwordHash, + role, + nim, + avatar, + profil_bevy, + role_tim + }, + }); + return NextResponse.json(newMember, { status: 201 }); + } catch (error) { + console.error('Error:', error); + return NextResponse.json({ error: 'Failed to add user' }, { status: 500 }); + } + +} \ No newline at end of file diff --git a/components/CardName.tsx b/components/CardName.tsx index a4d80eb..d3b0cec 100644 --- a/components/CardName.tsx +++ b/components/CardName.tsx @@ -3,7 +3,7 @@ import Link from "next/link"; /** * @param {object} props - the props containing the details of the person * @param {string} props.name - the name of the person - * @param {string} props.role - the role of the person + * @param {string} - the role of the person * @param {string} props.picture - the picture of the person * @param {string} props.profile_url - the profile url of the person * @returns {JSX.Element} - the article card component @@ -11,14 +11,14 @@ import Link from "next/link"; interface CardNameProps { name: string; - role: string; + roleTim: string; picture: string; profile_url: string; } export default function CardName({ name, - role, + roleTim, picture, profile_url, }: CardNameProps) { @@ -37,7 +37,7 @@ export default function CardName({

{name}

{/* show the role */} -

{role}

+

{roleTim}

); diff --git a/prisma/migrations/20250108215542_add_colom_profile/migration.sql b/prisma/migrations/20250108215542_add_colom_profile/migration.sql new file mode 100644 index 0000000..56778be --- /dev/null +++ b/prisma/migrations/20250108215542_add_colom_profile/migration.sql @@ -0,0 +1,8 @@ +/* + Warnings: + + - Added the required column `profil_bevy` to the `User` table without a default value. This is not possible if the table is not empty. + +*/ +-- AlterTable +ALTER TABLE `user` ADD COLUMN `profil_bevy` VARCHAR(191) NOT NULL; diff --git a/prisma/migrations/20250108221102_change_structure_profile/migration.sql b/prisma/migrations/20250108221102_change_structure_profile/migration.sql new file mode 100644 index 0000000..d00c3ed --- /dev/null +++ b/prisma/migrations/20250108221102_change_structure_profile/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE `user` MODIFY `profil_bevy` VARCHAR(191) NULL; diff --git a/prisma/migrations/20250108222906_add_role_tim/migration.sql b/prisma/migrations/20250108222906_add_role_tim/migration.sql new file mode 100644 index 0000000..b567e96 --- /dev/null +++ b/prisma/migrations/20250108222906_add_role_tim/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE `user` ADD COLUMN `role_time` VARCHAR(191) NULL; diff --git a/prisma/migrations/20250108223101_add_role_tim_2/migration.sql b/prisma/migrations/20250108223101_add_role_tim_2/migration.sql new file mode 100644 index 0000000..65f82dd --- /dev/null +++ b/prisma/migrations/20250108223101_add_role_tim_2/migration.sql @@ -0,0 +1,9 @@ +/* + Warnings: + + - You are about to drop the column `role_time` on the `user` table. All the data in the column will be lost. + +*/ +-- AlterTable +ALTER TABLE `user` DROP COLUMN `role_time`, + ADD COLUMN `role_tim` VARCHAR(191) NULL; diff --git a/prisma/migrations/20250109190225_add_role_tim_def/migration.sql b/prisma/migrations/20250109190225_add_role_tim_def/migration.sql new file mode 100644 index 0000000..f045c0a --- /dev/null +++ b/prisma/migrations/20250109190225_add_role_tim_def/migration.sql @@ -0,0 +1,8 @@ +/* + Warnings: + + - Made the column `role_tim` on table `user` required. This step will fail if there are existing NULL values in that column. + +*/ +-- AlterTable +ALTER TABLE `user` MODIFY `role_tim` ENUM('LEAD', 'COM_ADV', 'AFM', 'CORETIM') NOT NULL DEFAULT 'CORETIM'; diff --git a/prisma/migrations/20250109205240_add_role_tim_member/migration.sql b/prisma/migrations/20250109205240_add_role_tim_member/migration.sql new file mode 100644 index 0000000..9fed10a --- /dev/null +++ b/prisma/migrations/20250109205240_add_role_tim_member/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE `user` MODIFY `role_tim` ENUM('LEAD', 'COM_ADV', 'AFM', 'CORETIM', 'MEMBER') NOT NULL DEFAULT 'MEMBER'; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 44f8c1d..0296383 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -10,6 +10,13 @@ enum Role { ADMIN SUPERADMIN } +enum RoleTim { + LEAD + COM_ADV + AFM + CORETIM + MEMBER +} generator client { provider = "prisma-client-js" @@ -36,6 +43,8 @@ model User { role Role @default(MEMBER) email String @unique password String + profil_bevy String? + role_tim RoleTim @default(MEMBER) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt quizzes Quiz[] diff --git a/prisma/seed.ts b/prisma/seed.ts index 6ec5118..f5c16b6 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -10,14 +10,49 @@ async function main() { update: {}, create: { id: "d5f2e78c-c9e0-45d6-b577-5af5c196e9d2", - nim: "220535608548", + nim: "123456789", name: "Alvalen Shafelbilyunazra", email: "admin@admin.com", - avatar: "https://res.cloudinary.com/startup-grind/image/upload/c_fill,w_250,h_250,g_center/c_fill,dpr_2.0,f_auto,g_center,q_auto:good/v1/gcs/platform-data-goog/avatars/alvalen_shafel_5fUEnek.jpg", + avatar: "https://res.cloudinary.com/startup-grind/image/upload/c_fill,w_250,h_250,g_center/c_fill,dpr_2.0,f_auto,g_center,q_auto:good/v1/gcs/platform-data-goog/avatars/alvian_rahmadani_ikZ8sYg.jpg", role: "SUPERADMIN", + role_tim: "CORETIM", + profil_bevy: "https://gdg.community.dev/u/myfmmz/", + password, + }, + }); + const user2 = await prisma.user.upsert({ + where: { email: "admin2@gmail.com" }, + update: {}, + create: { + id: "d5f2e78c-c9e0-45d6-b577-5af5c196e9d1", + nim: "987654321", + name: "Budi 0 1", + email: "admin2@gmail.com", + role_tim: "CORETIM", + profil_bevy: "https://gdg.community.dev/u/myfmmz/", + avatar: "https://res.cloudinary.com/startup-grind/image/upload/c_fill,w_250,h_250,g_center/c_fill,dpr_2.0,f_auto,g_center,q_auto:good/v1/gcs/platform-data-goog/avatars/alvalen_shafel_5fUEnek.jpg", + role: "ADMIN", + password, }, }); + const user3 = await prisma.user.upsert({ + where: { email: "admin3@gmail.com" }, + update: {}, + create: { + id: "d5f2e78c-c9e0-45d6-b577-5af5c196e9d5", + nim: "147852369", + name: "Budi 0 1", + email: "admin3@gmail.com", + role_tim: "CORETIM", + profil_bevy: "https://gdg.community.dev/u/myfmmz/", + avatar: "https://res.cloudinary.com/startup-grind/image/upload/c_fill,w_250,h_250,g_center/c_fill,dpr_2.0,f_auto,g_center,q_auto:good/v1/gcs/platform-data-goog/avatars/alvalen_shafel_5fUEnek.jpg", + role: "MEMBER", + + password, + }, + }); + const artikel = await prisma.article.create({