-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added data query table and modules (#69)
* added data_query table * added DataQuery model objects * added data query api * removed cyclic dependencies * moved dataquery objects to core * data query delete * updated arena-core dependency * solved SonarCloud issue --------- Co-authored-by: Stefano Ricci <[email protected]>
- Loading branch information
Showing
36 changed files
with
653 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
import { Express } from 'express' | ||
|
||
import { ExpressInitializer } from '../server' | ||
import { ChainApi } from './chain' | ||
|
||
import { AuthApi } from './auth' | ||
import { ChainApi } from './chain' | ||
import { DataQueryApi } from './dataQuery' | ||
|
||
export const Api: ExpressInitializer = { | ||
init: (express: Express): void => { | ||
ChainApi.init(express) | ||
AuthApi.init(express) | ||
ChainApi.init(express) | ||
DataQueryApi.init(express) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Express } from 'express' | ||
|
||
import { ServiceRegistry } from '@openforis/arena-core' | ||
|
||
import { ExpressInitializer } from '../../server' | ||
import { ServerServiceType } from '../../server/arenaServer/serverServiceType' | ||
import { DataQueryService } from '../../service' | ||
import { Requests } from '../../utils' | ||
|
||
import { ApiEndpoint } from '../endpoint' | ||
|
||
const getDataQueryService = (): DataQueryService => | ||
ServiceRegistry.getInstance().getService(ServerServiceType.dataQuery) | ||
|
||
export const DataQueryCreate: ExpressInitializer = { | ||
init: (express: Express): void => { | ||
express.post(ApiEndpoint.dataQuery.dataQuery(':surveyId', ':queryUuid'), async (req, res, next) => { | ||
try { | ||
const { surveyId } = Requests.getParams(req) | ||
const querySummary = req.body | ||
|
||
const service = getDataQueryService() | ||
|
||
const querySummaryInserted = await service.insert({ surveyId, item: querySummary }) | ||
|
||
res.json(querySummaryInserted) | ||
} catch (error) { | ||
next(error) | ||
} | ||
}) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Express } from 'express' | ||
|
||
import { ServiceRegistry } from '@openforis/arena-core' | ||
|
||
import { ExpressInitializer } from '../../server' | ||
import { ServerServiceType } from '../../server/arenaServer/serverServiceType' | ||
import { DataQueryService } from '../../service' | ||
import { Requests } from '../../utils' | ||
|
||
import { ApiEndpoint } from '../endpoint' | ||
|
||
const getDataQueryService = (): DataQueryService => | ||
ServiceRegistry.getInstance().getService(ServerServiceType.dataQuery) | ||
|
||
export const DataQueryDelete: ExpressInitializer = { | ||
init: (express: Express): void => { | ||
express.delete(ApiEndpoint.dataQuery.dataQuery(':surveyId', ':queryUuid'), async (req, res, next) => { | ||
try { | ||
const { surveyId, queryUuid } = Requests.getParams(req) | ||
|
||
const service = getDataQueryService() | ||
|
||
const querySummaryUpdated = await service.deleteItem({ surveyId, uuid: queryUuid }) | ||
|
||
res.json(querySummaryUpdated) | ||
} catch (error) { | ||
next(error) | ||
} | ||
}) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Express } from 'express' | ||
|
||
import { ExpressInitializer } from '../../server' | ||
import { DataQueryRead } from './read' | ||
import { DataQueryCreate } from './create' | ||
import { DataQueryUpdate } from './update' | ||
import { DataQueryDelete } from './delete' | ||
|
||
export const DataQueryApi: ExpressInitializer = { | ||
init: (express: Express): void => { | ||
DataQueryCreate.init(express) | ||
DataQueryRead.init(express) | ||
DataQueryUpdate.init(express) | ||
DataQueryDelete.init(express) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { Express } from 'express' | ||
|
||
import { ServiceRegistry } from '@openforis/arena-core' | ||
|
||
import { ExpressInitializer } from '../../server' | ||
import { ServerServiceType } from '../../server/arenaServer/serverServiceType' | ||
import { DataQueryService } from '../../service' | ||
import { Requests } from '../../utils' | ||
|
||
import { ApiEndpoint } from '../endpoint' | ||
|
||
const getDataQueryService = (): DataQueryService => | ||
ServiceRegistry.getInstance().getService(ServerServiceType.dataQuery) as DataQueryService | ||
|
||
export const DataQueryRead: ExpressInitializer = { | ||
init: (express: Express): void => { | ||
express.get(ApiEndpoint.dataQuery.dataQueriesCount(':surveyId'), async (req, res, next) => { | ||
try { | ||
const { surveyId } = Requests.getParams(req) | ||
|
||
const service = getDataQueryService() | ||
|
||
const count = await service.count({ surveyId }) | ||
|
||
res.json({ count }) | ||
} catch (error) { | ||
next(error) | ||
} | ||
}) | ||
|
||
express.get(ApiEndpoint.dataQuery.dataQueries(':surveyId'), async (req, res, next) => { | ||
try { | ||
const { surveyId } = Requests.getParams(req) | ||
|
||
const service = getDataQueryService() | ||
|
||
const list = await service.getAll({ surveyId }) | ||
|
||
res.json({ list }) | ||
} catch (error) { | ||
next(error) | ||
} | ||
}) | ||
|
||
express.get(ApiEndpoint.dataQuery.dataQuery(':surveyId', ':querySummaryUuid'), async (req, res, next) => { | ||
try { | ||
const { surveyId, querySummaryUuid } = Requests.getParams(req) | ||
|
||
const service = getDataQueryService() | ||
|
||
const dataQuerySummary = await service.getByUuid({ surveyId, uuid: querySummaryUuid }) | ||
|
||
res.json(dataQuerySummary) | ||
} catch (error) { | ||
next(error) | ||
} | ||
}) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Express } from 'express' | ||
|
||
import { ServiceRegistry } from '@openforis/arena-core' | ||
|
||
import { ExpressInitializer } from '../../server' | ||
import { ServerServiceType } from '../../server/arenaServer/serverServiceType' | ||
import { DataQueryService } from '../../service' | ||
import { Requests } from '../../utils' | ||
|
||
import { ApiEndpoint } from '../endpoint' | ||
|
||
const getDataQueryService = (): DataQueryService => | ||
ServiceRegistry.getInstance().getService(ServerServiceType.dataQuery) | ||
|
||
export const DataQueryUpdate: ExpressInitializer = { | ||
init: (express: Express): void => { | ||
express.put(ApiEndpoint.dataQuery.dataQuery(':surveyId', ':queryUuid'), async (req, res, next) => { | ||
try { | ||
const { surveyId } = Requests.getParams(req) | ||
const querySummary = req.body | ||
|
||
const service = getDataQueryService() | ||
|
||
const querySummaryUpdated = await service.update({ surveyId, item: querySummary }) | ||
|
||
res.json(querySummaryUpdated) | ||
} catch (error) { | ||
next(error) | ||
} | ||
}) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { getApiPathSurvey } from './common' | ||
|
||
const moduleName = 'data_queries' | ||
|
||
export const dataQuery = { | ||
dataQueriesCount: (surveyId: string): string => getApiPathSurvey(surveyId, moduleName, 'count'), | ||
dataQueries: (surveyId: string): string => getApiPathSurvey(surveyId, moduleName), | ||
dataQuery: (surveyId: string, querySummaryUuid: string): string => | ||
getApiPathSurvey(surveyId, moduleName, querySummaryUuid), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { auth } from './auth' | ||
import { chain } from './chain' | ||
import { dataQuery } from './dataQuery' | ||
|
||
export const ApiEndpoint = { | ||
auth, | ||
chain, | ||
dataQuery, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/db/dbMigrator/migration/survey/migrations/20240403130324-add-table-data-query.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', '20240403130324-add-table-data-query-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', '20240403130324-add-table-data-query-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, | ||
} |
1 change: 1 addition & 0 deletions
1
.../dbMigrator/migration/survey/migrations/sqls/20240403130324-add-table-data-query-down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/* Replace with your SQL commands */ |
Oops, something went wrong.