CJVT updates August and September 2026
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
const { rm } = require('fs/promises')
|
||||
const { promisify } = require('util')
|
||||
const user = require('../../../middleware/user')
|
||||
const Dictionary = require('../../../models/dictionary')
|
||||
const User = require('../../../models/user')
|
||||
const Entry = require('../../../models/entry')
|
||||
const Extraction = require('../../../models/extraction')
|
||||
const email = require('../../../models/email')
|
||||
const {
|
||||
searchEntryIndex,
|
||||
deleteEntryFromIndex,
|
||||
@@ -11,11 +14,28 @@ const {
|
||||
const genEditorAllQuery = require('../../../models/helpers/search/generate-query/editor/all')
|
||||
const { prepareEditorEntries } = require('../../../models/helpers/search')
|
||||
const { DEFAULT_HITS_PER_PAGE } = require('../../../config/settings')
|
||||
const { minEntriesRequirementCheckAndAct } = require('../../helpers/dictionary')
|
||||
const {
|
||||
minEntriesRequirementCheckAndAct,
|
||||
resolveDictionarySort,
|
||||
parseDictionaryListFilters
|
||||
} = require('../../helpers/dictionary')
|
||||
const { getExportFilesPath } = require('../../../models/helpers/dictionary')
|
||||
|
||||
const dictionary = {}
|
||||
|
||||
dictionary.checkNameCollision = async (req, res) => {
|
||||
const { nameSl, nameSlShort, nameEn, excludeDictionaryId } = req.query
|
||||
|
||||
const collision = await Dictionary.checkNameCollision({
|
||||
nameSl: nameSl || null,
|
||||
nameSlShort: nameSlShort || null,
|
||||
nameEn: nameEn || null,
|
||||
excludeDictionaryId: excludeDictionaryId || null
|
||||
})
|
||||
|
||||
res.send({ collision })
|
||||
}
|
||||
|
||||
dictionary.getEntry = async (req, res) => {
|
||||
const entryId = req.query.id
|
||||
const [entry, domainLabels] = await Promise.all([
|
||||
@@ -133,6 +153,16 @@ dictionary.delete = async (req, res) => {
|
||||
res.end()
|
||||
}
|
||||
|
||||
dictionary.deleteExport = async (req, res) => {
|
||||
const dictionaryId = +req.params.dictionaryId
|
||||
const exportId = +req.params.exportId
|
||||
await Dictionary.deleteExport(dictionaryId, exportId)
|
||||
const exportFilePath = `${getExportFilesPath(dictionaryId)}/${exportId}`
|
||||
await rm(exportFilePath, { force: true })
|
||||
|
||||
res.end()
|
||||
}
|
||||
|
||||
dictionary.updateDomainLabels = [
|
||||
(req, res, next) => {
|
||||
req.dictionaryId = req.body.params.dictionaryId
|
||||
@@ -166,17 +196,65 @@ dictionary.listDictionaries = async (req, res) => {
|
||||
const resultsPerPage = req.user?.hitsPerPage || DEFAULT_HITS_PER_PAGE
|
||||
|
||||
const page = +req.query.p > 0 ? +req.query.p : 1
|
||||
const { sortBy, sortDir } = resolveDictionarySort(
|
||||
req.query.sort,
|
||||
req.query.dir
|
||||
)
|
||||
const filters = parseDictionaryListFilters(req.query)
|
||||
|
||||
const { pages_total: numberOfAllPages, results } =
|
||||
await Dictionary.fetchAllAdminDictionaries(
|
||||
req.determinedLanguage,
|
||||
resultsPerPage,
|
||||
page
|
||||
page,
|
||||
sortBy,
|
||||
sortDir,
|
||||
filters
|
||||
)
|
||||
|
||||
res.send({ page, numberOfAllPages, results })
|
||||
}
|
||||
|
||||
dictionary.contactDictionaryAuthors = async (req, res) => {
|
||||
const { dictionaryId } = req.params
|
||||
const { message } = req.body
|
||||
|
||||
const [name, recipients] = await Promise.all([
|
||||
Dictionary.fetchName(dictionaryId, req.determinedLanguage),
|
||||
User.fetchAllWithDictionaryRights(dictionaryId)
|
||||
])
|
||||
|
||||
const renderAsync = promisify(req.app.render.bind(req.app))
|
||||
const senderName = `${req.user.firstName} ${req.user.lastName}`
|
||||
const emailSubject = req.t('Sporočilo o slovarju "{{name}}"', { name })
|
||||
|
||||
await Promise.all(
|
||||
recipients.map(async recipient => {
|
||||
const emailHtml = await renderAsync(
|
||||
`email/dictionary-contact-authors_${recipient.language}`,
|
||||
{
|
||||
senderName,
|
||||
senderEmail: req.user.email,
|
||||
dictionaryName: name,
|
||||
message
|
||||
}
|
||||
)
|
||||
await email.send({
|
||||
to: recipient.email,
|
||||
subject: emailSubject,
|
||||
html: emailHtml,
|
||||
replyTo: req.user.email
|
||||
})
|
||||
})
|
||||
)
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(
|
||||
`Sent email to ${recipients.map(r => r.email)} (subject: ${emailSubject})`
|
||||
)
|
||||
|
||||
res.status(201).send()
|
||||
}
|
||||
|
||||
dictionary.listDomainLabels = async (req, res) => {
|
||||
const resultsPerPage = req.user?.hitsPerPage || DEFAULT_HITS_PER_PAGE
|
||||
const { dictionaryId } = req.params
|
||||
@@ -312,7 +390,10 @@ dictionary.exportBegin = async (req, res) => {
|
||||
req.body.isLanguageReviewedFilter === 'on'
|
||||
? undefined
|
||||
: req.body.isLanguageReviewedFilter,
|
||||
exportFileFormat: req.body.exportFileFormat
|
||||
exportFileFormat: req.body.exportFileFormat,
|
||||
timeZone: Intl.supportedValuesOf('timeZone').includes(req.body.timeZone)
|
||||
? req.body.timeZone
|
||||
: 'UTC'
|
||||
}
|
||||
|
||||
const exportId = await Dictionary.beginExport(dictionaryId, exportParams)
|
||||
|
||||
Reference in New Issue
Block a user