Skip to content

Commit

Permalink
fix: update resource blueprint
Browse files Browse the repository at this point in the history
  • Loading branch information
davewasmer committed Feb 5, 2018
1 parent b0c9ba2 commit 66396e2
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 11 deletions.
3 changes: 3 additions & 0 deletions blueprints/model/files/app/models/__name__.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
import ApplicationModel from './application';

export default class <%= className %>Model extends ApplicationModel {

static schema = {};

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import ApplicationAction from '../application';
import <%= singular.className %> from '../../models/<%= singular.dasherized %>';

export default class Create<%= singular.className %> extends ApplicationAction {

async respond({ body }) {
let post = await this.db.create('<%= singular.dasherized %>', body).save();
this.render(201, post);
let <%= singular.camelCased %> = await <%= singular.className %>.create(body);
this.render(201, <%= singular.camelCased %>);
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import ApplicationAction from '../application';
import <%= singular.className %> from '../../models/<%= singular.dasherized %>';

export default class Destroy<%= singular.className %> extends ApplicationAction {

async respond({ params }) {
let post = await this.db.find('<%= singular.dasherized %>', params.id);
await post.destroy();
let <%= singular.camelCased %> = await <%= singular.className %>.find(params.id);
await <%= singular.camelCased %>.destroy();
this.render(204);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import ApplicationAction from '../application';
import <%= singular.className %> from '../../models/<%= singular.dasherized %>';

export default class List<%= plural.className %> extends ApplicationAction {

async respond() {
return await this.db.all('<%= singular.dasherized %>');
return await <%= singular.className %>.all();
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import ApplicationAction from '../application';
import <%= singular.className %> from '../../models/<%= singular.dasherized %>';

export default class Show<%= singular.className %> extends ApplicationAction {

async respond({ params }) {
return this.db.find('<%= singular.dasherized %>', params.id);
return await <%= singular.className %>.find(params.id);
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import ApplicationAction from '../application';
import <%= singular.className %> from '../../models/<%= singular.dasherized %>';

export default class Update<%= singular.className %> extends ApplicationAction {

async respond({ params, body }) {
let post = await this.db.find('<%= singular.dasherized %>', params.id);
Object.assign(post, body);
return await post.save();
let <%= singular.camelCased %> = await <%= singular.className %>.find(params.id);
Object.assign(<%= singular.camelCased %>, body);
return await <%= singular.camelCased %>.save();
}

}
4 changes: 2 additions & 2 deletions blueprints/resource/files/app/models/__singular.name__.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { attr /* , hasOne, hasMany */ } from 'denali';
import { /* attr, hasOne, hasMany */ } from 'denali';
import ApplicationModel from './application';

export default class <%= singular.className %> extends ApplicationModel {

// static title = attr('text');
static schema = {};

}

0 comments on commit 66396e2

Please sign in to comment.