-
Notifications
You must be signed in to change notification settings - Fork 9
Hello. I decided to solve Demo task ExpressBoilerplate. #5
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
base: master
Are you sure you want to change the base?
Changes from all commits
d6fa055
b275327
6d96e5b
80a1bf0
0b819f0
ee88dee
d592e8c
00bd033
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,8 +4,12 @@ const m = attract('core/models'); | |
| module.exports = { | ||
| create: async (req, res, next) => { | ||
| try { | ||
| const user = await m.user.create(req.body); | ||
| return res.render('users', user); | ||
| await m.user.create(req.body); | ||
| return res.render('users', { | ||
| section: 'Users', | ||
| users: await m.user.find({ 'meta.status': 'active' }), | ||
| cities: await m.city.find({ 'meta.status': 'active' }) | ||
| }); | ||
| } catch (error) { | ||
| return next(error); | ||
| } | ||
|
|
@@ -15,18 +19,20 @@ module.exports = { | |
| if (req.params.user) { | ||
| return res.send(await m.user.findById(req.params.user)); | ||
| } | ||
|
|
||
| return res.render('users', { | ||
| section: 'Users', | ||
| users: await m.user.find({ 'meta.status': 'active' }) | ||
| users: await m.user.find({ 'meta.status': 'active' }), | ||
| cities: await m.city.find({ 'meta.status': 'active' }) | ||
| }); | ||
| }, | ||
|
|
||
| delete: async (req, res, next) => { | ||
| try { | ||
| const user = await m.user.findById(req.params.user).exec(); | ||
| const user = await m.user.findById(req.params.user) | ||
| .exec(); | ||
| await user.remove(); | ||
| return res.status(200).end(); | ||
| return res.status(200) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Response for a
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not change anything significant here, the editor optimized the markup of the code |
||
| .end('success'); | ||
| } catch (error) { | ||
| return next(error); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| module.exports = (grunt, path) => { | ||
| grunt.registerTask('watch', ['watch']); | ||
| return { | ||
| scripts: { | ||
| files: [ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| $(document) | ||
| .ready(() => { | ||
| $('body .delete-user').click((ev) => { | ||
| $.ajax({ | ||
| url: `/users/${$(ev.target).attr('_id')}`, | ||
| type: 'DELETE', | ||
| success() { | ||
| $(ev.target).closest('tr').remove(); | ||
| } | ||
| }); | ||
| }); | ||
| $('body .delete-city').click((ev) => { | ||
| $.ajax({ | ||
| url: `/cities/${$(ev.target).attr('_id')}`, | ||
| type: 'DELETE', | ||
| success() { | ||
| $(ev.target).closest('tr').remove(); | ||
| } | ||
| }); | ||
| }); | ||
| $('body .update-city').click((ev) => { | ||
| const cityId = $(ev.target).attr('_idd'); | ||
| const cityname = $(`.city_name_${cityId}`).val(); | ||
| $.ajax({ | ||
| url: `/cities/${$(ev.target).attr('_id')}`, | ||
| type: 'PUT', | ||
| data: { | ||
| name: cityname | ||
| } | ||
| }); | ||
| }); | ||
| }); |
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.
No need to have this here, as it is already in the drop-in task.
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.
But without it here command 'grunt watch' doesn't work at me correctly.
And official documentation (https://github.com/gruntjs/grunt-contrib-watch) says
npm install grunt-contrib-watch --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-contrib-watch');
I'll better remove it from file /grunt/watch.task.js
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 meant this line:
grunt.loadNpmTasks('grunt-contrib-watch');which is already loaded in the drop-in task.