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

Added survey config column #72

Merged
merged 3 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,40 @@
"types": "dist/index.d.ts",
"devDependencies": {
"@machinomy/types-node-db-migrate": "^0.0.2",
"@types/bcryptjs": "^2.4.4",
"@types/compression": "^1.7.3",
"@types/connect-pg-simple": "^7.0.1",
"@types/db-migrate-base": "^0.0.10",
"@types/bcryptjs": "^2.4.6",
"@types/compression": "^1.7.5",
"@types/connect-pg-simple": "^7.0.3",
"@types/db-migrate-base": "^0.0.14",
"@types/express": "^4.17.14",
"@types/express-fileupload": "^1.4.1",
"@types/express-session": "^1.17.5",
"@types/jest": "^29.5.5",
"@types/lodash.throttle": "^4.1.7",
"@types/lodash.throttle": "^4.1.9",
"@types/passport": "^1.0.12",
"@types/passport-local": "^1.0.35",
"@types/supertest": "^2.0.12",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@typescript-eslint/parser": "^6.7.0",
"copyfiles": "^2.4.1",
"dotenv": "^16.3.1",
"dotenv": "^16.4.5",
"eslint": "^8.49.0",
"husky": "8.0.3",
"jest": "^29.7.0",
"lint-staged": "^14.0.1",
"npm-run-all": "^4.1.5",
"prettier": "3.0.3",
"prettier": "3.3.3",
"rimraf": "^5.0.1",
"supertest": "^6.3.3",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
"typescript": "^5.6.2"
},
"dependencies": {
"@godaddy/terminus": "^4.12.1",
"@openforis/arena-core": "^0.0.188",
"@openforis/arena-core": "^0.0.205",
"bcryptjs": "^2.4.3",
"compression": "^1.7.4",
"connect-pg-simple": "^9.0.0",
"connect-pg-simple": "^10.0.0",
"db-migrate": "^0.11.14",
"db-migrate-pg": "^1.5.2",
"express": "^4.18.2",
Expand All @@ -53,8 +53,8 @@
"log4js": "^6.9.1",
"passport": "^0.6.0",
"passport-local": "^1.0.0",
"pg-promise": "^11.5.4",
"socket.io": "^4.7.2"
"pg-promise": "^11.9.1",
"socket.io": "^4.8.0"
},
"scripts": {
"build": "run-s tsc copy-assets",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
'use strict'

var dbm
var type
var seed
var fs = require('fs')
var path = require('path')
var Promise

/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function (options, seedLink) {
dbm = options.dbmigrate
type = dbm.dataType
seed = seedLink
Promise = options.Promise
}

exports.up = function (db) {
var filePath = path.join(__dirname, 'sqls', '20240927095011-add-column-survey-config-up.sql')
return new Promise(function (resolve, reject) {
fs.readFile(filePath, { encoding: 'utf-8' }, function (err, data) {
if (err) return reject(err)
console.log('received data: ' + data)

resolve(data)
})
}).then(function (data) {
return db.runSql(data)
})
}

exports.down = function (db) {
var filePath = path.join(__dirname, 'sqls', '20240927095011-add-column-survey-config-down.sql')
return new Promise(function (resolve, reject) {
fs.readFile(filePath, { encoding: 'utf-8' }, function (err, data) {
if (err) return reject(err)
console.log('received data: ' + data)

resolve(data)
})
}).then(function (data) {
return db.runSql(data)
})
}

exports._meta = {
version: 1,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* Replace with your SQL commands */
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE survey
ADD COLUMN config jsonb NULL;
11 changes: 3 additions & 8 deletions src/repository/chain/count.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { ChainProps, Objects } from '@openforis/arena-core'
import { DB, SqlSelectBuilder, TableChain } from '../../db'

export const count = (options: { cycle: string; surveyId: number }, client = DB): Promise<number> => {
const { cycle, surveyId } = options
export const count = (options: { surveyId: number }, client = DB): Promise<number> => {
const { surveyId } = options

const table = new TableChain(surveyId)
const sql = new SqlSelectBuilder()
.select(`count(${table.alias}.*)`)
.from(table)
.where(`(${table.props})->'${Objects.propertyOf<ChainProps>('cycles')}' @> '"${cycle}"'`)
.build()
const sql = new SqlSelectBuilder().select(`count(${table.alias}.*)`).from(table).build()

return client.one<number>(sql, [], (res) => res.count)
}
Loading
Loading