-
Notifications
You must be signed in to change notification settings - Fork 0
prepare user grouping #161
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
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,13 @@ | ||
| import { getApiPathSurvey } from './common' | ||
|
|
||
| const moduleName = 'user-groups' | ||
|
|
||
| export const userGroup = { | ||
| userGroups: (surveyId: string): string => getApiPathSurvey(surveyId, moduleName), | ||
| userGroupsCount: (surveyId: string): string => getApiPathSurvey(surveyId, moduleName, 'count'), | ||
| userGroup: (surveyId: string, groupUuid: string): string => getApiPathSurvey(surveyId, moduleName, groupUuid), | ||
| userGroupMembers: (surveyId: string, groupUuid: string): string => | ||
| getApiPathSurvey(surveyId, moduleName, groupUuid, 'members'), | ||
| userGroupMember: (surveyId: string, groupUuid: string, userUuid: string): string => | ||
| getApiPathSurvey(surveyId, moduleName, groupUuid, 'members', userUuid), | ||
| } |
This file contains hidden or 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 hidden or 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,64 @@ | ||
| import { Express } from 'express' | ||
|
|
||
| import { ServiceRegistry, ServiceType, SurveyService } from '@openforis/arena-core' | ||
|
|
||
| import { ExpressInitializer } from '../../server' | ||
| import { ServerServiceType } from '../../server/arenaServer/serverServiceType' | ||
| import { UserGroupService } from '../../service' | ||
| import { Requests } from '../../utils' | ||
|
|
||
| import { ApiEndpoint } from '../endpoint' | ||
| import { ApiAuthMiddleware } from '../middleware' | ||
|
|
||
| const { requireUserGroupManagePermission } = ApiAuthMiddleware | ||
|
|
||
| const getUserGroupService = (): UserGroupService => | ||
| ServiceRegistry.getInstance().getService(ServerServiceType.userGroup) as UserGroupService | ||
|
|
||
| const getSurveyUuid = async (surveyId: number): Promise<string> => { | ||
| const surveyService = ServiceRegistry.getInstance().getService(ServiceType.survey) as SurveyService | ||
| const survey = await surveyService.get({ surveyId }) | ||
| return survey.uuid | ||
| } | ||
|
|
||
| export const UserGroupCreate: ExpressInitializer = { | ||
| init: (express: Express): void => { | ||
| express.post( | ||
| ApiEndpoint.userGroup.userGroups(':surveyId'), | ||
| requireUserGroupManagePermission, | ||
| async (req, res, next) => { | ||
| try { | ||
| const { surveyId } = Requests.getParams(req) | ||
| const item = req.body | ||
|
|
||
| const surveyUuid = await getSurveyUuid(surveyId) | ||
|
|
||
| const service = getUserGroupService() | ||
| const userGroupInserted = await service.insert({ surveyUuid, item }) | ||
|
|
||
| res.json(userGroupInserted) | ||
| } catch (error) { | ||
| next(error) | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| express.post( | ||
| ApiEndpoint.userGroup.userGroupMembers(':surveyId', ':groupUuid'), | ||
| requireUserGroupManagePermission, | ||
| async (req, res, next) => { | ||
| try { | ||
| const { groupUuid } = Requests.getParams(req) | ||
| const { userUuid } = req.body | ||
|
|
||
| const service = getUserGroupService() | ||
| await service.addMember({ groupUuid, userUuid }) | ||
|
|
||
| res.json({ groupUuid, userUuid }) | ||
| } catch (error) { | ||
| next(error) | ||
| } | ||
| } | ||
| ) | ||
| }, | ||
| } |
This file contains hidden or 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,54 @@ | ||
| import { Express } from 'express' | ||
|
|
||
| import { ServiceRegistry } from '@openforis/arena-core' | ||
|
|
||
| import { ExpressInitializer } from '../../server' | ||
| import { ServerServiceType } from '../../server/arenaServer/serverServiceType' | ||
| import { UserGroupService } from '../../service' | ||
| import { Requests } from '../../utils' | ||
|
|
||
| import { ApiEndpoint } from '../endpoint' | ||
| import { ApiAuthMiddleware } from '../middleware' | ||
|
|
||
| const { requireUserGroupManagePermission } = ApiAuthMiddleware | ||
|
|
||
| const getUserGroupService = (): UserGroupService => | ||
| ServiceRegistry.getInstance().getService(ServerServiceType.userGroup) as UserGroupService | ||
|
|
||
| export const UserGroupDelete: ExpressInitializer = { | ||
| init: (express: Express): void => { | ||
| express.delete( | ||
| ApiEndpoint.userGroup.userGroup(':surveyId', ':groupUuid'), | ||
| requireUserGroupManagePermission, | ||
| async (req, res, next) => { | ||
| try { | ||
| const { groupUuid } = Requests.getParams(req) | ||
|
|
||
| const service = getUserGroupService() | ||
| const userGroupDeleted = await service.deleteItem({ uuid: groupUuid }) | ||
|
|
||
| res.json(userGroupDeleted) | ||
| } catch (error) { | ||
| next(error) | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| express.delete( | ||
| ApiEndpoint.userGroup.userGroupMember(':surveyId', ':groupUuid', ':userUuid'), | ||
| requireUserGroupManagePermission, | ||
| async (req, res, next) => { | ||
| try { | ||
| const { groupUuid, userUuid } = Requests.getParams(req) | ||
|
|
||
| const service = getUserGroupService() | ||
| await service.removeMember({ groupUuid, userUuid }) | ||
|
|
||
| res.json({ groupUuid, userUuid }) | ||
|
SteRiccio marked this conversation as resolved.
Outdated
|
||
| } catch (error) { | ||
| next(error) | ||
| } | ||
| } | ||
| ) | ||
| }, | ||
| } | ||
This file contains hidden or 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 { UserGroupCreate } from './create' | ||
| import { UserGroupRead } from './read' | ||
| import { UserGroupUpdate } from './update' | ||
| import { UserGroupDelete } from './delete' | ||
|
|
||
| export const UserGroupApi: ExpressInitializer = { | ||
| init: (express: Express): void => { | ||
| UserGroupCreate.init(express) | ||
| UserGroupRead.init(express) | ||
| UserGroupUpdate.init(express) | ||
| UserGroupDelete.init(express) | ||
| }, | ||
| } |
This file contains hidden or 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,92 @@ | ||
| import { Express } from 'express' | ||
|
|
||
| import { ServiceRegistry, ServiceType, SurveyService } from '@openforis/arena-core' | ||
|
|
||
| import { ExpressInitializer } from '../../server' | ||
| import { ServerServiceType } from '../../server/arenaServer/serverServiceType' | ||
| import { UserGroupService } from '../../service' | ||
| import { Requests } from '../../utils' | ||
|
|
||
| import { ApiEndpoint } from '../endpoint' | ||
| import { ApiAuthMiddleware } from '../middleware' | ||
|
|
||
| const { requireSurveyViewPermission } = ApiAuthMiddleware | ||
|
|
||
| const getUserGroupService = (): UserGroupService => | ||
| ServiceRegistry.getInstance().getService(ServerServiceType.userGroup) as UserGroupService | ||
|
|
||
| const getSurveyUuid = async (surveyId: number): Promise<string> => { | ||
| const surveyService = ServiceRegistry.getInstance().getService(ServiceType.survey) as SurveyService | ||
| const survey = await surveyService.get({ surveyId }) | ||
| return survey.uuid | ||
| } | ||
|
|
||
| export const UserGroupRead: ExpressInitializer = { | ||
| init: (express: Express): void => { | ||
| express.get( | ||
| ApiEndpoint.userGroup.userGroupsCount(':surveyId'), | ||
| requireSurveyViewPermission, | ||
| async (req, res, next) => { | ||
| try { | ||
| const { surveyId } = Requests.getParams(req) | ||
| const surveyUuid = await getSurveyUuid(surveyId) | ||
|
|
||
| const service = getUserGroupService() | ||
| const count = await service.count({ surveyUuid }) | ||
|
|
||
| res.json({ count }) | ||
| } catch (error) { | ||
| next(error) | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| express.get(ApiEndpoint.userGroup.userGroups(':surveyId'), requireSurveyViewPermission, async (req, res, next) => { | ||
| try { | ||
| const { surveyId } = Requests.getParams(req) | ||
| const surveyUuid = await getSurveyUuid(surveyId) | ||
|
|
||
| const service = getUserGroupService() | ||
| const list = await service.getAll({ surveyUuid }) | ||
|
|
||
| res.json({ list }) | ||
| } catch (error) { | ||
| next(error) | ||
| } | ||
| }) | ||
|
|
||
| express.get( | ||
| ApiEndpoint.userGroup.userGroup(':surveyId', ':groupUuid'), | ||
| requireSurveyViewPermission, | ||
| async (req, res, next) => { | ||
| try { | ||
| const { groupUuid } = Requests.getParams(req) | ||
|
|
||
| const service = getUserGroupService() | ||
| const userGroup = await service.getByUuid({ uuid: groupUuid }) | ||
|
|
||
| res.json(userGroup) | ||
|
SteRiccio marked this conversation as resolved.
Outdated
|
||
| } catch (error) { | ||
| next(error) | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| express.get( | ||
| ApiEndpoint.userGroup.userGroupMembers(':surveyId', ':groupUuid'), | ||
| requireSurveyViewPermission, | ||
| async (req, res, next) => { | ||
| try { | ||
| const { groupUuid } = Requests.getParams(req) | ||
|
|
||
| const service = getUserGroupService() | ||
| const list = await service.getMembers({ groupUuid }) | ||
|
|
||
| res.json({ list }) | ||
| } catch (error) { | ||
| next(error) | ||
| } | ||
| } | ||
| ) | ||
| }, | ||
| } | ||
This file contains hidden or 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,38 @@ | ||
| import { Express } from 'express' | ||
|
|
||
| import { ServiceRegistry } from '@openforis/arena-core' | ||
|
|
||
| import { ExpressInitializer } from '../../server' | ||
| import { ServerServiceType } from '../../server/arenaServer/serverServiceType' | ||
| import { UserGroupService } from '../../service' | ||
| import { Requests } from '../../utils' | ||
|
|
||
| import { ApiEndpoint } from '../endpoint' | ||
| import { ApiAuthMiddleware } from '../middleware' | ||
|
|
||
| const { requireUserGroupManagePermission } = ApiAuthMiddleware | ||
|
|
||
| const getUserGroupService = (): UserGroupService => | ||
| ServiceRegistry.getInstance().getService(ServerServiceType.userGroup) as UserGroupService | ||
|
|
||
| export const UserGroupUpdate: ExpressInitializer = { | ||
| init: (express: Express): void => { | ||
| express.put( | ||
| ApiEndpoint.userGroup.userGroup(':surveyId', ':groupUuid'), | ||
| requireUserGroupManagePermission, | ||
| async (req, res, next) => { | ||
| try { | ||
| const { groupUuid } = Requests.getParams(req) | ||
| const { props } = req.body | ||
|
|
||
| const service = getUserGroupService() | ||
| const userGroupUpdated = await service.update({ uuid: groupUuid, props }) | ||
|
|
||
| res.json(userGroupUpdated) | ||
|
SteRiccio marked this conversation as resolved.
Outdated
|
||
| } catch (error) { | ||
| next(error) | ||
| } | ||
| } | ||
| ) | ||
| }, | ||
| } | ||
45 changes: 45 additions & 0 deletions
45
src/db/dbMigrator/migration/public/migrations/20260713124754-create-user-group-tables.js
This file contains hidden or 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,45 @@ | ||
| 'use strict' | ||
|
|
||
| var dbm | ||
| var type | ||
| var seed | ||
| var fs = require('fs') | ||
| var path = require('path') | ||
| var Promise | ||
|
|
||
| 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', '20260713124754-create-user-group-tables-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', '20260713124754-create-user-group-tables-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, | ||
| } |
2 changes: 2 additions & 0 deletions
2
...igrator/migration/public/migrations/sqls/20260713124754-create-user-group-tables-down.sql
This file contains hidden or 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,2 @@ | ||
| DROP TABLE IF EXISTS user_group_user; | ||
| DROP TABLE IF EXISTS user_group; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.