"use strict";var m=Object.defineProperty;var u=(l,s)=>m(l,"name",{value:s,configurable:true});const n=use("App/Models/Workspace");const{validateAll:o}=use("Validator");const{v4:g}=require("uuid");const{convertToJSON:v}=require("../../../../jsUtils");class w{async create({request:s,response:r}){const t=await o(s.all(),{name:"required"});if(t.fails()){return r.status(401).send({message:"Invalid POST arguments",messages:t.messages(),status:401})}const a=s.all();let e;do{e=g()}while((await n.query().where("workspaceId",e).fetch()).rows.length>0);const d=await n.all();const c=d.rows.length;const{name:i}=a;delete a.name;await n.create({workspaceId:e,name:i,order:c,services:JSON.stringify([]),data:JSON.stringify(a)});return r.send({userId:1,name:i,id:e,order:c,workspaces:[]})}async edit({request:s,response:r,params:t}){const a=await o(s.all(),{name:"required"});if(a.fails()){return r.status(401).send({message:"Invalid POST arguments",messages:a.messages(),status:401})}const e=s.all();const{id:d}=t;await n.query().where("workspaceId",d).update({name:e.name,services:JSON.stringify(e.services)});const c=await n.query().where("workspaceId",d).fetch();const i=c.rows[0];return r.send({id:i.workspaceId,name:e.name,order:i.order,services:e.services,userId:1})}async delete({response:s,params:r}){const t=await o(r,{id:"required"});if(t.fails()){return s.status(401).send({message:"Invalid arguments",messages:t.messages(),status:401})}const{id:a}=r;await n.query().where("workspaceId",a).delete();return s.send({message:"Successfully deleted workspace"})}async list({response:s}){const r=await n.all();const t=r.rows;let a=[];if(t){a=t.map(e=>({id:e.workspaceId,name:e.name,order:e.order,services:v(e.services),userId:1}))}return s.send(a)}}u(w,"WorkspaceController");module.exports=w;
