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

Feature/ebp api integration #1214

Draft
wants to merge 29 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
753ba13
feat(ebp-upload): add etrs89GridCode cell in birds forms
onyxvd Oct 24, 2024
300ad08
feat(ebp-upload): add empty upload to EBP task with some api params d…
onyxvd Oct 24, 2024
d903d4e
feat(ebp-upload): create etrs89_cell model and migration
onyxvd Oct 25, 2024
69875d6
feat(ebp-upload): create task for filling missing etrs89 grid codes
onyxvd Oct 25, 2024
99ce780
feat(ebp-upload): create action for triggering etrs89 task
onyxvd Oct 25, 2024
9d234c4
feat(ebp-upload): fix etrs89_cell model
onyxvd Nov 22, 2024
f7c4a81
feat(ebp-upload): add birds_ebp model
onyxvd Nov 26, 2024
6e179f9
fixup! feat(ebp-upload): add birds_ebp model
onyxvd Nov 27, 2024
ee17986
fixup! fixup! feat(ebp-upload): add birds_ebp model
onyxvd Nov 27, 2024
90e5515
feat(ebp-upload): add ebp_birds_status model
onyxvd Nov 27, 2024
8ea94e2
feat(ebp-upload): add ebp api token env to server container
onyxvd Nov 28, 2024
d80057f
feat(ebp-upload): wip prepare data for upload
onyxvd Nov 28, 2024
1d83124
fixup! feat(ebp-upload): wip prepare data for upload
onyxvd Nov 29, 2024
1847450
fixup! feat(ebp-upload): wip prepare data for upload
onyxvd Dec 2, 2024
c553f24
feat(ebp-upload): send data to EBP
onyxvd Dec 9, 2024
70f7424
fixup! feat(ebp-upload): send data to EBP
onyxvd Dec 9, 2024
c0a22ed
feat(ebp-upload): add task action
onyxvd Dec 11, 2024
db1541d
fixup! fixup! feat(ebp-upload): send data to EBP
onyxvd Dec 12, 2024
c456909
fixup! fixup! fixup! feat(ebp-upload): send data to EBP
onyxvd Dec 12, 2024
5400dbe
feat(ebp-upload): add ebp-species settings
onyxvd Dec 13, 2024
34105fa
fixup! feat(ebp-upload): add ebp-species settings
onyxvd Dec 17, 2024
ee144b9
feat(ebp-upload): support updating ebp species
onyxvd Jan 7, 2025
dfb17ab
feat(ebp-upload): support updating ebp species statuses
onyxvd Jan 7, 2025
f6776ee
feat(ebp-upload): support updating ebp allowed organizations
onyxvd Jan 8, 2025
ba0973f
feat(ebp-upload): support updating ebp allowed sources
onyxvd Jan 9, 2025
a4765a0
feat(ebp-upload): support updating ebp upload protocol
onyxvd Jan 9, 2025
a8918e9
feat(ebp-upload): change some routes
onyxvd Jan 10, 2025
a2b2512
feat(ebp-upload): read ebp organizations and sources from the settings
onyxvd Jan 10, 2025
0be7aad
feat(ebp-upload): update bg and en translations
onyxvd Jan 10, 2025
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
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
BACKUP_ZIP_PASSWORD=<zip-password>
SB_DOMAIN=sb.localhost
EBP_API_TOKEN=<ebp-api-token>
6 changes: 6 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ services:
build: .
entrypoint: ./entrypoint.sh
command: start
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
# env_file:
# - sb-server.env
environment:
Expand All @@ -51,6 +56,7 @@ services:
REDIS_HOST: redis
REDIS_PORT: 6379
REDIS_DB: 0
EBP_API_TOKEN: ${EBP_API_TOKEN}
depends_on:
redis:
condition: service_healthy
Expand Down
445 changes: 398 additions & 47 deletions i18n/bg.json

Large diffs are not rendered by default.

437 changes: 399 additions & 38 deletions i18n/en.json

Large diffs are not rendered by default.

331 changes: 331 additions & 0 deletions server/actions/ebp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,331 @@
const paging = require('../helpers/paging')
const incremental = require('../helpers/incremental')
const { upgradeAction } = require('../utils/upgrade')
const Promise = require('bluebird')

exports.ebbSpeciesList = upgradeAction('ah17', {
name: 'ebp:speciesList',
description: 'ebp:speciesList',
middleware: ['admin'],
inputs: paging.declareInputs(incremental.declareInputs({
filter: {}
})),

run: function (api, data, next) {
try {
let q = {
order: [['sbNameLa', 'ASC']]
}
q = paging.prepareQuery(q, data.params)
return api.models.ebp_birds.findAndCountAll(q).then(function (result) {
data.response.count = result.count
data.response.meta = incremental.generateMeta(data, paging.generateMeta(result.count, data))
data.response.data = result.rows.map(function (ebpSpecies) {
return ebpSpecies.apiData(api)
})
return next()
}).catch(function (e) {
console.error('Failure for list EBP species', e)
return next(e)
})
} catch (e) {
console.error(e)
return next(e)
}
}
})

exports.ebbSpeciesUpdate = upgradeAction('ah17', {
name: 'ebp:speciesUpdate',
description: 'ebp:speciesUpdate',
middleware: ['admin'],
inputs: {
items: { required: true }
},

run: function (api, data, next) {
Promise.resolve()
.then(function () {
if (!(data.params.items instanceof Array)) {
data.connection.rawConnection.responseHttpCode = 400
throw new Error('items is not array')
}
if (data.params.items.length <= 0) {
data.connection.rawConnection.responseHttpCode = 400
throw new Error('cannot update with empty items')
}
return data.params.items.map(function (item) {
const record = api.models.ebp_birds.build({})
record.apiUpdate(item)
return record
})
})
.then(function (models) {
return api.sequelize.sequelize.transaction(function (t) {
return api.models.ebp_birds
.destroy({
where: {},
transaction: t
})
.then(function (deleted) {
api.log('replacing ebp_birds %d with %d', 'info', deleted, models.length)
})
.then(function () {
return Promise.map(models, function (item) {
return item.save({ transaction: t }).then((m) => m.apiData())
})
})
})
})
.then(function (result) {
data.response.count = result.length
data.response.data = result
})
.then(function () {
return next()
}, function (e) {
api.log('Failure to update ebp_birds', 'error', e)
return next(e)
})
}
})

exports.ebpSpeciesStatusList = upgradeAction('ah17', {
name: 'ebp:speciesStatusList',
description: 'ebp:speciesStatusList',
middleware: ['admin'],

run: function (api, data, next) {
try {
const q = {
order: [['ebpId', 'ASC']]
}
return api.models.ebp_birds_status.findAndCountAll(q).then(function (result) {
data.response.count = result.count
data.response.data = result.rows.map(function (ebpSpeciesStatus) {
return ebpSpeciesStatus.apiData(api)
})
return next()
}).catch(function (e) {
console.error('Failure for list EBP species statuses', e)
return next(e)
})
} catch (e) {
console.error(e)
return next(e)
}
}
})

exports.ebbSpeciesStatusUpdate = upgradeAction('ah17', {
name: 'ebp:speciesStatusUpdate',
description: 'ebp:speciesStatusUpdate',
middleware: ['admin'],
inputs: {
items: { required: true }
},

run: function (api, data, next) {
Promise.resolve()
.then(function () {
if (!(data.params.items instanceof Array)) {
data.connection.rawConnection.responseHttpCode = 400
throw new Error('items is not array')
}
if (data.params.items.length <= 0) {
data.connection.rawConnection.responseHttpCode = 400
throw new Error('cannot update with empty items')
}
return data.params.items.map(function (item) {
const record = api.models.ebp_birds_status.build({})
record.apiUpdate(item)
return record
})
})
.then(function (models) {
return api.sequelize.sequelize.transaction(function (t) {
return api.models.ebp_birds_status
.destroy({
where: {},
transaction: t
})
.then(function (deleted) {
api.log('replacing ebp_birds_status %d with %d', 'info', deleted, models.length)
})
.then(function () {
return Promise.map(models, function (item) {
return item.save({ transaction: t }).then((m) => m.apiData())
})
})
})
})
.then(function (result) {
data.response.count = result.length
data.response.data = result
})
.then(function () {
return next()
}, function (e) {
api.log('Failure to update ebp_birds_status', 'error', e)
return next(e)
})
}
})

exports.ebpOrganizationsList = upgradeAction('ah17', {
name: 'ebp:organizationsList',
description: 'ebp:organizationsList',
middleware: ['admin'],

run: function (api, data, next) {
try {
return api.models.settings.findOne({
where: {
name: 'ebp_organizations'
}
}).then(function (ebpOrganizations) {
data.response.data = JSON.parse(ebpOrganizations?.value || '[]')
return next()
})
} catch (e) {
console.error(e)
return next(e)
}
}
})

exports.ebpOrganizationsUpdate = upgradeAction('ah17', {
name: 'ebp:organizationsUpdate',
description: 'ebp:organizationsUpdate',
middleware: ['admin'],
inputs: {
items: { required: true }
},
run: function (api, data, next) {
try {
return api.models.settings.findOne({
where: {
name: 'ebp_organizations'
}
}).then(function (ebpOrganizations) {
if (!ebpOrganizations) {
ebpOrganizations = api.models.settings.build({
name: 'ebp_organizations'
})
}
ebpOrganizations.value = JSON.stringify(data.params.items)
ebpOrganizations.save()
return next()
})
} catch (e) {
console.error(e)
return next(e)
}
}
})

exports.ebpSourcesList = upgradeAction('ah17', {
name: 'ebp:sourcesList',
description: 'ebp:sourcesList',
middleware: ['admin'],

run: function (api, data, next) {
try {
return api.models.settings.findOne({
where: {
name: 'ebp_sources'
}
}).then(function (ebpSources) {
data.response.data = JSON.parse(ebpSources?.value || '[]')
return next()
})
} catch (e) {
console.error(e)
return next(e)
}
}
})

exports.ebpSourcesUpdate = upgradeAction('ah17', {
name: 'ebp:sourcesUpdate',
description: 'ebp:sourcesUpdate',
middleware: ['admin'],
inputs: {
items: { required: true }
},
run: function (api, data, next) {
try {
return api.models.settings.findOne({
where: {
name: 'ebp_sources'
}
}).then(function (ebpSources) {
if (!ebpSources) {
ebpSources = api.models.settings.build({
name: 'ebp_sources'
})
}
ebpSources.value = JSON.stringify(data.params.items)
ebpSources.save()
return next()
})
} catch (e) {
console.error(e)
return next(e)
}
}
})

exports.ebpProtocolGet = upgradeAction('ah17', {
name: 'ebp:protocolGet',
description: 'ebp:protocolGet',
middleware: ['admin'],

run: function (api, data, next) {
try {
return api.models.settings.findOne({
where: {
name: 'ebp_protocol'
}
}).then(function (setting) {
data.response.data = {
protocol: setting?.value || ''
}
return next()
})
} catch (e) {
console.error(e)
return next(e)
}
}
})

exports.ebpProtocolUpdate = upgradeAction('ah17', {
name: 'ebp:protocolUpdate',
description: 'ebp:protocolUpdate',
middleware: ['admin'],
inputs: {
protocol: {}
},
run: function (api, data, next) {
try {
return api.models.settings.findOne({
where: {
name: 'ebp_protocol'
}
}).then(function (setting) {
if (!setting) {
setting = api.models.settings.build({
name: 'ebp_protocol'
})
}
setting.value = data.params.protocol
setting.save()
return next()
})
} catch (e) {
console.error(e)
return next(e)
}
}
})
Loading
Loading