632SZPUQC6KX3CDZLYWV22OSFIOG66CJ7PONRNTXYTFLQX3JFFXQC
export async function save(
id_: DurableObjectId,
params: RouteParams,
request: Request,
platform: Readonly<App.Platform>,
) {
const f = await request.formData()
const data_ = f.get('data')
let data
if (data_) {
console.log("data", data_)
data = JSON.parse(data_ as string)
if (!SimulationCommunaute(data)) {
throw error(400, "Bad request")
}
} else {
throw error(400, "Bad request")
}
const name = <string>f.get('name') || ''
const porteur = <string>f.get('porteur') || ''
const adresse = <string>f.get('adresse') || ''
const tel = <string>f.get('tel') || ''
const photo = <string | null>f.get('photo')
console.log("params!", params)
let pid
if (params['id'] == "nouveau") {
pid = await userForm(platform.env, id_, {
CreateProjet: {
name,
porteur,
tel,
adresse,
simulation: data
}
})
} else {
pid = params['id']
await userForm(platform.env, id_, {
SaveProjet: {
id: params['id'],
name,
porteur,
tel,
adresse,
simulation: data
}
})
}
console.log(pid, !!photo)
if (photo) {
console.log("photo")
try {
console.log("f")
console.log(photo)
await platform.env.projets.put(`photo.${id_.toString()}.${pid}`, photo)
console.log("put")
} catch (e) {
console.log("Error", JSON.stringify(e))
}
}
console.log("redirect", `${base}/projet/${pid}`)
throw redirect(302, `${base}/projet/${pid}`)
}
export async function del(
id_: DurableObjectId,
params: RouteParams,
platform: Readonly<App.Platform>
) {
await userForm(platform.env, id_, {
DelProjet: {
id: params['id'],
}
})
throw redirect(302, `${base}`)
}
export async function save(
id_: DurableObjectId,
params: RouteParams,
request: Request,
platform: Readonly<App.Platform>,
) {
const f = await request.formData()
const data_ = f.get('data')
let data
if (data_) {
console.log("data", data_)
data = JSON.parse(data_ as string)
if (!SimulationCommunaute(data)) {
throw error(400, "Bad request")
}
} else {
throw error(400, "Bad request")
}
const name = <string>f.get('name') || ''
const porteur = <string>f.get('porteur') || ''
const adresse = <string>f.get('adresse') || ''
const tel = <string>f.get('tel') || ''
const photo = <string | null>f.get('photo')
console.log("params!", params)
let pid
if (params['id'] == "nouveau") {
pid = await userForm(platform.env, id_, {
CreateProjet: {
name,
porteur,
tel,
adresse,
simulation: data
}
})
} else {
pid = params['id']
await userForm(platform.env, id_, {
SaveProjet: {
id: params['id'],
name,
porteur,
tel,
adresse,
simulation: data
}
})
}
console.log(pid, !!photo)
if (photo) {
console.log("photo")
try {
console.log("f")
console.log(photo)
await platform.env.projets.put(`photo.${id_.toString()}.${pid}`, photo)
console.log("put")
} catch (e) {
console.log("Error", JSON.stringify(e))
}
}
console.log("redirect", `${base}/projet/${pid}`)
throw redirect(302, `${base}/projet/${pid}`)
}
export async function del(
id_: DurableObjectId,
params: RouteParams,
platform: Readonly<App.Platform>
) {
await userForm(platform.env, id_, {
DelProjet: {
id: params['id'],
}
})
throw redirect(302, `${base}`)
}