You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
only delete note doesn't work, it's 400 bad request.There are no messages in the command line.
If commented out, everything works fine. (422 is expected behavior)
Here is the complete code.
import{Elysia,t}from"elysia";classNote{constructor(publicdata: string[]=['Moonhalo','Bonjour']){}add(note: string){this.data.push(note)returnthis.data}remove(id: number){returnthis.data.splice(id,1)}update(id: number,note: string){return(this.data[id]=note)}}exportconstnote=newElysia({prefix: '/note'}).decorate('note',newNote())// .onTransform(function log({ body, params, path, request: { method } }) {// console.log(`${method} ${path}`, {// body,// params// })// }).get('/',({ note })=>note.data).post('/',({ note,body: { data }})=>note.add(data),{body: t.Object({data: t.String()})}).guard({params: t.Object({id: t.Number()})}).get('/:id',({ note,params: { id }, error })=>{returnnote.data[id]??error(404,'oh no :(')},).delete('/:id',({ note,params: { id }, error })=>{if(idinnote.data)returnnote.remove(id)returnerror(422,'not found note')},).patch('/:id',({ note,params: { id },body: { data }, error })=>{if(idinnote.data)returnnote.update(id,data)returnerror(422,'not found note')},{body: t.Object({data: t.String()})})
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
after add this lifecycle method
only
delete note
doesn't work, it's 400 bad request.There are no messages in the command line.If commented out, everything works fine. (422 is expected behavior)
Here is the complete code.
Beta Was this translation helpful? Give feedback.
All reactions