-
-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat/add CRUD messages #152
base: main
Are you sure you want to change the base?
Conversation
src/models/Message.ts
Outdated
body!: string | ||
|
||
@prop({ required: true }) | ||
userId!: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's do author
and link the User
model here
src/controllers/message.ts
Outdated
|
||
@Put('/:id') | ||
async updateMessage(@Params('id') id: string, @Body() { content }: { content: string }) { | ||
return await MessageModel.findByIdAndUpdate(id, { content }, { new: true }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't have to do return await
, read up on promises and why return await
is unnecessary
src/controllers/message.ts
Outdated
|
||
@Delete('/:id') | ||
async deleteMessage(@Params('id') id: string) { | ||
return await MessageModel.findByIdAndDelete |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this won't work. test your crud with postman or insomnia
body!: string | ||
|
||
@prop({ required: true, ref: () => User }) | ||
user!:Ref<User> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can call it author
also turn on fix on save for the linter, your formatting is broken
make sure yarn build
and yarn lint
pass
return ctx.throw(notFound()) | ||
} | ||
|
||
ctx.state['user'] = user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think you can do ctx.state.user
here
@@ -0,0 +1,34 @@ | |||
import { Context, Next } from 'koa' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call this file authenticate
, as a verb
} | ||
|
||
@Delete('/:messageId') | ||
deleteMessage(@State('message') message: DocumentType<Message>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sure to manually test everything with postman or insomnia
Add CRUD Messages