Skip to content

Commit acfcd54

Browse files
committed
entity
1 parent 1d4340d commit acfcd54

File tree

14 files changed

+98
-269
lines changed

14 files changed

+98
-269
lines changed

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ services:
1010
volumes:
1111
- dev_pg_data:/var/lib/postgresql/data
1212
environment:
13-
POSTGRES_DB: axis
13+
POSTGRES_DB: todo_manager
1414
POSTGRES_PASSWORD: secret
1515

1616
volumes:

package.json

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,15 @@
2323
"@graphql-tools/load-files": "^6.2.5",
2424
"@graphql-tools/merge": "^6.2.6",
2525
"@koa/cors": "^3.1.0",
26-
"@sendgrid/mail": "^7.4.2",
2726
"apollo-server": "^2.19.1",
2827
"apollo-server-koa": "^2.19.1",
29-
"aws-sdk": "^2.853.0",
30-
"axios": "^0.21.1",
31-
"bcryptjs": "^2.4.3",
3228
"bignumber.js": "^9.0.1",
3329
"colors": "^1.4.0",
34-
"dataloader": "^2.0.0",
3530
"dotenv": "^8.2.0",
3631
"graphql": "^15.5.0",
3732
"graphql-scalars": "^1.7.0",
3833
"graphql-tools": "^7.0.2",
3934
"graphql-upload": "^11.0.0",
40-
"handlebars": "^4.7.7",
41-
"jsonwebtoken": "^8.5.1",
4235
"knex": "^0.95.6",
4336
"koa": "^2.13.1",
4437
"koa-body": "^4.2.0",
@@ -47,15 +40,11 @@
4740
"koa-trace": "^1.0.1",
4841
"lodash": "^4.17.20",
4942
"module-alias": "^2.2.2",
50-
"moment": "^2.29.1",
5143
"ms": "^2.1.3",
5244
"objection": "^2.2.4",
5345
"pg": "^8.5.1",
5446
"pluralize": "^8.0.0",
55-
"randomatic": "^3.1.1",
5647
"stack-chain": "^2.0.0",
57-
"url-join": "^4.0.1",
58-
"urlify": "^0.3.6",
5948
"validatorjs": "^3.22.1"
6049
},
6150
"devDependencies": {

src/components/book/controller.js

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,12 @@
1-
const { Book } = require('@/entities/book')
1+
const { TodoList } = require('@/entities/TodoList')
2+
const { BaseController } = require('@/lib/classes/BaseController')
23

3-
class BookController {
4-
static async find (query) {
5-
return Book.query().skipUndefined().where(query)
6-
}
7-
8-
static async insert (data) {
9-
return Book.query().insert(data).returning('*')
10-
}
11-
12-
static async update (id, data) {
13-
return Book.query().findById(id).patch(data).returning('*')
14-
}
15-
16-
static async deleteById (id) {
17-
return Book.query().deleteById(id)
18-
}
19-
20-
static opencrud = {
21-
find: async (query, { orderBy, skip, limit } = {}) => {
22-
return Book.query()
23-
.skipUndefined()
24-
.where(Book.opencrud.buildWhere(query))
25-
.orderBy(Book.opencrud.parseOrderBy(orderBy))
26-
.offset(skip)
27-
.limit(limit)
28-
},
29-
30-
count: async query => {
31-
return Book.query()
32-
.where(Book.opencrud.buildWhere(query))
33-
.count('id')
34-
.then(([{ count }]) => count)
35-
},
36-
37-
findOne: async query => {
38-
return Book.query()
39-
.findOne(Book.opencrud.buildWhere(query))
40-
}
4+
class TodoListController extends BaseController {
5+
static get Model () {
6+
return TodoList
417
}
428
}
439

4410
module.exports = {
45-
BookController
11+
TodoListController
4612
}
Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
1-
const { BookController } = require('../controller')
1+
const { TodoListController } = require('../controller')
22
const { NotFoundError } = require('@/lib/errors')
33

4-
class BookResolver {
4+
class TodoListResolver {
55
static resolvers () {
66
return {
77
Query: {
8-
book: async (_, { where }, { account }) => {
9-
const book = await BookController.opencrud.findOne(where)
10-
if (!book) throw new NotFoundError('Book not found')
8+
countTodoLists: async (_, { where }) =>
9+
TodoListController.count(where),
10+
todoLists: async (_, { where, skip, limit }) =>
11+
TodoListController.find(where, { skip, limit }),
12+
todoList: async (_, { where }) => {
13+
const todoList = await TodoListController.findOne(where)
14+
if (!todoList) throw new NotFoundError('TodoList not found')
1115

12-
return book
13-
},
14-
books: async (_, { where, orderBy, skip, limit }, { account }) => {
15-
return {
16-
totalCount: await BookController.opencrud.count(where),
17-
list: await BookController.opencrud.find(where, { orderBy, skip, limit })
18-
}
16+
return todoList
1917
}
2018
},
2119
Mutation: {
22-
createBook: async (_, { data, authorId }, { account }) => BookController.insert({ ...data, authorId }),
23-
updateBook: (_, { id, data }, { account }) => BookController.update(id, data),
24-
deleteBook: (_, { id }, { account }) => BookController.deleteById(id).then(() => true)
20+
createTodoList: async (_, { data, authorId }) => TodoListController.insert({ ...data, authorId }),
21+
updateTodoList: (_, { id, data }) => TodoListController.update(id, data),
22+
deleteTodoList: (_, { id }) => TodoListController.deleteById(id).then(() => true)
2523
},
26-
Book: {
27-
// author: (parent, _, ctx) => this.dataLoaders(ctx, 'author', AuthController).load(parent.authorId),
28-
// comments: (parent, _, ctx) => this.dataLoaders(ctx, 'comments', CommentController, { multi: true, field: 'bookId' }).load(parent.id)
24+
TodoList: {
25+
// items => (parent) => TodoList.fetchRelated('items')
2926
}
3027
}
3128
}
3229
}
3330

34-
module.exports = BookResolver.resolvers()
31+
module.exports = TodoListResolver.resolvers()
Lines changed: 4 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,21 @@
1-
type Books {
2-
totalCount: Int!
3-
list: [Book!]!
4-
}
5-
6-
type Book {
1+
type TodoList {
72
id: Int!
83
title: String!
9-
author: Author!
10-
comments: [Comment!]!
114
createdAt: DateTime!
125
updatedAt: DateTime!
136
}
147

15-
input BookCreateInput {
8+
input TodoListCreateInput {
169
title: String!
1710
}
1811

19-
input BookUpdateInput {
12+
input TodoListUpdateInput {
2013
title: String
2114
}
2215

23-
input BookWhereInput {
24-
AND: [BookWhereInput]
25-
OR: [BookWhereInput]
26-
16+
input TodoListWhereInput {
2717
id: Int
28-
id_not: Int
29-
id_lt: Int
30-
id_lte: Int
31-
id_gt: Int
32-
id_gte: Int
33-
id_in: [Int]
34-
id_not_in: [Int]
35-
3618
title: String
37-
title_not: String
38-
title_contains: String
39-
title_not_contains: String
40-
title_starts_with: String
41-
title_not_starts_with: String
42-
title_ends_with: String
43-
title_not_ends_with: String
44-
title_lt: String
45-
title_lte: String
46-
title_gt: String
47-
title_gte: String
48-
title_in: [String]
49-
title_not_in: [String]
50-
5119
createdAt: DateTime
52-
createdAt_not: DateTime
53-
createdAt_in: [DateTime]
54-
createdAt_not_in: [DateTime]
55-
createdAt_lt: DateTime
56-
createdAt_lte: DateTime
57-
createdAt_gt: DateTime
58-
createdAt_gte: DateTime
59-
6020
updatedAt: DateTime
61-
updatedAt_not: DateTime
62-
updatedAt_in: [DateTime]
63-
updatedAt_not_in: [DateTime]
64-
updatedAt_lt: DateTime
65-
updatedAt_lte: DateTime
66-
updatedAt_gt: DateTime
67-
updatedAt_gte: DateTime
68-
69-
}
70-
71-
enum BookOrderByInput {
72-
id_ASC
73-
id_DESC
74-
title_ASC
75-
title_DESC
76-
createdAt_ASC
77-
createdAt_DESC
78-
updatedAt_ASC
79-
updatedAt_DESC
8021
}
Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,15 @@
11
exports.up = function (knex) {
22
return knex.schema
3-
.createTable('accounts', function (table) {
3+
.createTable('todo_lists', function (table) {
44
table.increments('id')
55

6-
table.string('login', 64).notNullable().index().unique()
7-
table.string('password', 128).notNullable()
8-
table.string('refresh_token', 128)
9-
table.string('forgot_hash', 36)
10-
table.datetime('forgot_expiration')
11-
table.enum('role', [ 'ADMIN', 'USER' ]).notNullable()
12-
13-
table.timestamps(true, true)
14-
})
15-
16-
.createTable('books', function (table) {
17-
table.increments('id')
18-
19-
table.string('title', 128).notNullable()
20-
21-
table.integer('author_id')
22-
.references('id')
23-
.inTable('accounts')
24-
.onDelete('CASCADE')
25-
.index()
26-
27-
table.timestamps(true, true)
28-
})
29-
30-
.createTable('comments', function (table) {
31-
table.increments('id')
32-
33-
table.text('text').notNullable()
34-
35-
table.integer('comment_author_id')
36-
.references('id')
37-
.inTable('accounts')
38-
.onDelete('CASCADE')
39-
.notNullable()
40-
.index()
41-
42-
table.integer('author_id')
43-
.references('id')
44-
.inTable('accounts')
45-
.onDelete('CASCADE')
46-
.index()
47-
48-
table.integer('book_id')
49-
.references('id')
50-
.inTable('accounts')
51-
.onDelete('CASCADE')
52-
.index()
6+
table.string('title', 64).notNullable().index().unique()
537

548
table.timestamps(true, true)
559
})
5610
}
5711

5812
exports.down = function (knex) {
5913
return knex.schema
60-
.dropTableIfExists('comments')
61-
.dropTableIfExists('books')
62-
.dropTableIfExists('accounts')
14+
.dropTableIfExists('todo_list')
6315
}

src/database/seeds/00_accounts.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/entities/TodoList.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const { BaseModel } = require('@/lib/classes/BaseModel')
2+
3+
class TodoList extends BaseModel {
4+
static schema = {
5+
...super.schema,
6+
title: 'string|required'
7+
// if field not set in schema it won't be passed to DB
8+
}
9+
}
10+
11+
module.exports = {
12+
TodoList
13+
}

src/entities/book/index.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/entities/book/model.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)