(()=>{var e={};e.id=972,e.ids=[972],e.modules={3295:e=>{"use strict";e.exports=require("next/dist/server/app-render/after-task-async-storage.external.js")},5486:e=>{"use strict";e.exports=require("bcrypt")},10846:e=>{"use strict";e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},12909:(e,r,t)=>{"use strict";function s(){let e=process.env.JWT_SECRET;if(!e)throw Error("JWT_SECRET is not set");return e}function a(e){let r=e.headers.get("authorization");if(r&&r.startsWith("Bearer "))return r.slice(7);let t=e.cookies.get("admin_token")?.value;if(t)return t;let s=e.cookies.get("token")?.value;return s||null}t.d(r,{V:()=>a,u:()=>s})},27910:e=>{"use strict";e.exports=require("stream")},28354:e=>{"use strict";e.exports=require("util")},29294:e=>{"use strict";e.exports=require("next/dist/server/app-render/work-async-storage.external.js")},44870:e=>{"use strict";e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},55511:e=>{"use strict";e.exports=require("crypto")},63033:e=>{"use strict";e.exports=require("next/dist/server/app-render/work-unit-async-storage.external.js")},75675:(e,r,t)=>{"use strict";t.r(r),t.d(r,{patchFetch:()=>M,routeModule:()=>x,serverHooks:()=>N,workAsyncStorage:()=>v,workUnitAsyncStorage:()=>k});var s={};t.r(s),t.d(s,{GET:()=>f,PUT:()=>w});var a=t(96559),n=t(48088),i=t(37719),o=t(32190),u=t(96330),p=t(43205),c=t.n(p),d=t(12909);let m=new u.PrismaClient,l=(0,d.u)();function y(){return o.NextResponse.json({error:"Unauthorized"},{status:401})}function h(){return o.NextResponse.json({error:"Forbidden"},{status:403})}async function f(e,{params:r}){try{let t,s=(0,d.V)(e);if(!s)return y();try{t=c().verify(s,l)}catch{return y()}let a=t.companyId,n=parseInt(r.id);if(!a||Number.isNaN(n))return o.NextResponse.json({error:"Invalid payload"},{status:400});let i=await m.user.findUnique({where:{id:n},include:{userMarketplacePermissions:{include:{companyMarketplace:!0}}}}),u=await m.userSystemPermission.findMany({where:{userId:n},select:{permission:!0}});if(!i||i.companyId!==a)return h();let p=i.userMarketplacePermissions.map(e=>e.companyMarketplaceId),f=u.map(e=>e.permission);return o.NextResponse.json({id:i.id,email:i.email,name:i.name,surname:i.surname,phoneNumber:i.phoneNumber,isAdmin:i.isAdmin,marketplaceIds:p,systemPermissions:f})}catch(e){return console.error("Get user error:",e),o.NextResponse.json({error:"Server error"},{status:500})}}async function w(e,{params:r}){try{let s,a,n=(0,d.V)(e);if(!n)return y();try{s=c().verify(n,l)}catch{return y()}let i=s.companyId,u=s.userId,p=parseInt(r.id);if(!i||Number.isNaN(p))return o.NextResponse.json({error:"Invalid payload"},{status:400});if(!(await m.userSystemPermission.findMany({where:{userId:u},select:{permission:!0}})).some(e=>"USER_MANAGEMENT"===e.permission))return o.NextResponse.json({error:"Bu işlem i\xe7in yetkiniz bulunmuyor"},{status:403});let{email:f,password:w,name:x,surname:v,phoneNumber:k,isAdmin:N,marketplaceIds:M,systemPermissions:P}=await e.json(),j=await m.user.findUnique({where:{id:p}});if(!j||j.companyId!==i)return h();if(w&&w.length>0){let e=(await Promise.resolve().then(t.t.bind(t,5486,23))).default;a=await e.hash(w,10)}return await m.$transaction(async e=>{if(await e.user.update({where:{id:p},data:{email:f??j.email,password:a??j.password,name:x??j.name,surname:v??j.surname,phoneNumber:k??j.phoneNumber,isAdmin:N??j.isAdmin}}),await e.userMarketplacePermission.deleteMany({where:{userId:p}}),Array.isArray(M)&&M.length>0){let r=await e.companyMarketplace.findMany({where:{id:{in:M},companyId:i},select:{id:!0}});r.length>0&&await e.userMarketplacePermission.createMany({data:r.map(e=>({userId:p,companyMarketplaceId:e.id}))})}void 0!==P&&(await e.userSystemPermission.deleteMany({where:{userId:p}}),Array.isArray(P)&&P.length>0&&await e.userSystemPermission.createMany({data:P.map(e=>({userId:p,permission:e}))}))}),o.NextResponse.json({ok:!0})}catch(e){return console.error("Update user error:",e),o.NextResponse.json({error:"Server error"},{status:500})}}let x=new a.AppRouteRouteModule({definition:{kind:n.RouteKind.APP_ROUTE,page:"/api/company/users/[id]/route",pathname:"/api/company/users/[id]",filename:"route",bundlePath:"app/api/company/users/[id]/route"},resolvedPagePath:"/Users/mustafaseyhan/Project/PazarAnalist/src/app/api/company/users/[id]/route.ts",nextConfigOutput:"standalone",userland:s}),{workAsyncStorage:v,workUnitAsyncStorage:k,serverHooks:N}=x;function M(){return(0,i.patchFetch)({workAsyncStorage:v,workUnitAsyncStorage:k})}},78335:()=>{},79428:e=>{"use strict";e.exports=require("buffer")},96330:e=>{"use strict";e.exports=require("@prisma/client")},96487:()=>{}};var r=require("../../../../../webpack-runtime.js");r.C(e);var t=e=>r(r.s=e),s=r.X(0,[4447,580,3205],()=>t(75675));module.exports=s})();