"use strict";(()=>{var e={};e.id=68,e.ids=[68],e.modules={3524:e=>{e.exports=require("@prisma/client")},7096:e=>{e.exports=require("bcrypt")},9344:e=>{e.exports=require("jsonwebtoken")},145:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},6249:(e,r)=>{Object.defineProperty(r,"l",{enumerable:!0,get:function(){return function e(r,t){return t in r?r[t]:"then"in r&&"function"==typeof r.then?r.then(r=>e(r,t)):"function"==typeof r&&"default"===t?r:void 0}}})},3824:(e,r,t)=>{t.r(r),t.d(r,{config:()=>l,default:()=>c,routeModule:()=>f});var a={};t.r(a),t.d(a,{default:()=>d});var s=t(1802),n=t(7153),u=t(6249),i=t(2944),o=t(3481);async function d(e,r){if("POST"!==e.method)return r.status(405).json({success:!1,error:"Method not allowed"});if(!await (0,i.k)(e,r))return;let{id:t}=e.query,{role:a}=e.body||{};if("string"!=typeof t||"string"!=typeof a)return r.status(400).json({success:!1,error:"Invalid input"});try{let e=await o.K.updateUserRole(t,a);return r.status(200).json({success:!0,data:e})}catch(e){return console.error("Error updating role:",e),r.status(500).json({success:!1,error:"Failed to update role"})}}let c=(0,u.l)(a,"default"),l=(0,u.l)(a,"config"),f=new s.PagesAPIRouteModule({definition:{kind:n.x.PAGES_API,page:"/api/v1/admin/users/[id]/role",pathname:"/api/v1/admin/users/[id]/role",bundlePath:"",filename:""},userland:a})},3481:(e,r,t)=>{t.d(r,{K:()=>n});var a=t(1450),s=t(1026);let n={async getUserById(e){let r=await a.Z.user.findUnique({where:{id:e},select:{id:!0,username:!0,avatarUrl:!0,role:!0,status:!0,createdAt:!0,lastLogin:!0}});return r?{...r,role:r.role,createdAt:r.createdAt.toISOString(),lastLogin:r.lastLogin?.toISOString()||new Date().toISOString(),avatarUrl:r.avatarUrl||""}:null},getUserByUsername:async e=>a.Z.user.findUnique({where:{username:e}}),async createUser(e,r,t){let n=await (0,s.c_)(r),u=`https://api.dicebear.com/7.x/avataaars/svg?seed=${e}`;return a.Z.user.create({data:{username:e,password:n,avatarUrl:u,role:"CREATOR",status:"ACTIVE"}})},async authenticateUser(e,r){let t=await this.getUserByUsername(e);return t&&t.password&&await (0,s.Gv)(r,t.password)?(await a.Z.user.update({where:{id:t.id},data:{lastLogin:new Date}}),{id:t.id,username:t.username,avatarUrl:t.avatarUrl||"",role:t.role,status:t.status,createdAt:t.createdAt.toISOString(),lastLogin:new Date().toISOString()}):null},getAllUsers:async()=>a.Z.user.findMany({orderBy:{createdAt:"desc"}}),updateUser:async(e,r)=>a.Z.user.update({where:{id:e},data:{username:r.username,avatarUrl:r.avatarUrl}}),updateUserRole:async(e,r)=>a.Z.user.update({where:{id:e},data:{role:r}}),async toggleUserStatus(e){let r=await a.Z.user.findUnique({where:{id:e}});if(!r)throw Error("User not found");let t="ACTIVE"===r.status?"BANNED":"ACTIVE";return a.Z.user.update({where:{id:e},data:{status:t}})}}},1026:(e,r,t)=>{t.d(r,{Gv:()=>d,RA:()=>c,WX:()=>l,c_:()=>o});var a=t(7096),s=t.n(a),n=t(9344),u=t.n(n);function i(){let e=process.env.JWT_SECRET;if(!e)throw Error("JWT_SECRET is not set");return e}async function o(e){return s().hash(e,10)}async function d(e,r){return s().compare(e,r)}function c(e){return u().sign({userId:e},i(),{expiresIn:"7d"})}function l(e){try{return u().verify(e,i())}catch(e){return null}}},2944:(e,r,t)=>{t.d(r,{k:()=>n});var a=t(8103),s=t(7556);async function n(e,r){return!!await (0,a.m)(e,r)&&(e.user?.role===s.i.ADMIN||(r.status(403).json({success:!1,error:"Admin access required"}),!1))}},8103:(e,r,t)=>{t.d(r,{R:()=>u,m:()=>n});var a=t(1026),s=t(3481);async function n(e,r){let t=i(e);if(!t)return r.status(401).json({success:!1,error:"Authentication required"}),!1;let n=(0,a.WX)(t);if(!n)return r.status(401).json({success:!1,error:"Invalid or expired token"}),!1;let u=await s.K.getUserById(n.userId);return u?"BANNED"===u.status?(r.status(403).json({success:!1,error:"Account has been banned"}),!1):(e.user=u,!0):(r.status(401).json({success:!1,error:"User not found"}),!1)}async function u(e){let r=i(e);if(!r)return;let t=(0,a.WX)(r);if(!t)return;let n=await s.K.getUserById(t.userId);n&&"BANNED"!==n.status&&(e.user=n)}function i(e){if(e.cookies.token)return e.cookies.token;let r=e.headers.authorization;return r&&r.startsWith("Bearer ")?r.substring(7):null}},1450:(e,r,t)=>{t.d(r,{Z:()=>s});var a=t(3524);let s=globalThis.prisma??new a.PrismaClient},7556:(e,r,t)=>{var a,s;t.d(r,{i:()=>a}),function(e){e.USER="USER",e.ADMIN="ADMIN",e.CREATOR="CREATOR",e.MANAGER="MANAGER"}(a||(a={})),function(e){e.CODE="CODE",e.ASSET_ZIP="ASSET_ZIP",e.VIDEO="VIDEO"}(s||(s={}))},7153:(e,r)=>{var t;Object.defineProperty(r,"x",{enumerable:!0,get:function(){return t}}),function(e){e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE"}(t||(t={}))},1802:(e,r,t)=>{e.exports=t(145)}};var r=require("../../../../../../webpack-api-runtime.js");r.C(e);var t=r(r.s=3824);module.exports=t})();