Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

feat/add CRUD messages #152

wants to merge 2 commits into from

Conversation

prostoDo
Copy link

Add CRUD Messages

body!: string

@prop({ required: true })
userId!: string
Copy link
Member

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


@Put('/:id')
async updateMessage(@Params('id') id: string, @Body() { content }: { content: string }) {
return await MessageModel.findByIdAndUpdate(id, { content }, { new: true })
Copy link
Member

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


@Delete('/:id')
async deleteMessage(@Params('id') id: string) {
return await MessageModel.findByIdAndDelete
Copy link
Member

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

src/controllers/message.ts Show resolved Hide resolved
body!: string

@prop({ required: true, ref: () => User })
user!:Ref<User>
Copy link
Member

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
Copy link
Member

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'
Copy link
Member

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>) {
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants