Skip to content

Commit

Permalink
Merge pull request #29 from JWebCoder/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
JWebCoder authored Jul 26, 2019
2 parents 62e7c9b + 81edfe3 commit a364d0b
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 194 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"graphql": "^14.2.1",
"jsonschema": "^1.2.4",
"knex": "^0.17.3",
"metle": "^1.0.0",
"morgan": "^1.9.1",
"mysql2": "^1.6.4",
"pluralize": "^8.0.0",
Expand Down
25 changes: 19 additions & 6 deletions src/api/controllers/TableController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import {
runHook
} from '@root/api/utils'
import { normalize as normalizeData } from '@root/api/utils/data'
import memory from '@root/api/utils/memoryStorage'
import { IColumnRelation, IManyToOneRelation, ITableInfo } from '@root/configGenerator'
import Bluebird from 'bluebird'
import Debug from 'debug'
import { NextFunction } from 'express'
import Knex from 'knex'
import metle from 'metle'

const debug = Debug('funfunzmc:controller-table')

Expand Down Expand Up @@ -159,10 +159,10 @@ class TableController {
}
req.query.columns.forEach(
(column: string) => {
if (memory.hasItem('distinct_' + column)) {
if (metle.hasItem('distinct_' + column)) {
columns.toAdd.push({
name: column,
value: memory.getItem('distinct_' + column),
value: metle.getItem('distinct_' + column),
})
} else {
columns.toRequest.push(column)
Expand Down Expand Up @@ -204,7 +204,7 @@ class TableController {

Object.keys(results).forEach(
(column: string) => {
memory.setItem('distinct_' + column, results[column])
metle.setItem('distinct_' + column, results[column])
}
)

Expand Down Expand Up @@ -348,10 +348,16 @@ class TableController {
)

const newData = normalizeData(req.body.data, TABLE_CONFIG)

return Promise.all([
DB,
runHook(TABLE_CONFIG, 'updateRow', 'before', req, res, DB, newData),
])
}
).then(
([DB, data]) => {
let QUERY = DB(TABLE_NAME)
QUERY = applyPKFilters(QUERY, req.body, TABLE_CONFIG)
return QUERY.update(newData)
return QUERY.update(data)
}
).then(
(results) => {
Expand All @@ -374,6 +380,13 @@ class TableController {

return this.requirementsCheck(TABLE_CONFIG, req.user, database, next).then(
(DB) => {
return Promise.all([
DB,
runHook(TABLE_CONFIG, 'deleteRow', 'before', req, res, database.db),
])
}
).then(
([DB]) => {
let QUERY = DB(TABLE_NAME)
QUERY = applyPKFilters(QUERY, req.body, TABLE_CONFIG)
return QUERY.del()
Expand Down
6 changes: 3 additions & 3 deletions src/api/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import TablesController from '@root/api/controllers/TablesController'
import GraphQLSchema from '@root/api/graphql/schema'
import { sendJSON } from '@root/api/middleware/response'
import config from '@root/api/utils/configLoader'
import memory from '@root/api/utils/memoryStorage'
import { Response, Router } from 'express'
import graphqlHTTP from 'express-graphql'
import fs from 'fs'
import metle from 'metle'
import path from 'path'

class IndexRouter {
Expand Down Expand Up @@ -95,7 +95,7 @@ class IndexRouter {
}

this.router.get('*', function(req, res) {
const homePage: ILayout = memory.getItem('layout_homePage')
const homePage: ILayout = metle.getItem('layout_homePage')
if (homePage) {
sendHomePage(res, homePage)
} else {
Expand All @@ -116,7 +116,7 @@ class IndexRouter {
data,
}
}
memory.setItem('layout_homePage', newHomePage)
metle.setItem('layout_homePage', newHomePage)
sendHomePage(res, newHomePage)
})
}
Expand Down
119 changes: 0 additions & 119 deletions src/api/utils/memoryStorage.ts

This file was deleted.

66 changes: 0 additions & 66 deletions test/memory.test.ts

This file was deleted.

0 comments on commit a364d0b

Please sign in to comment.