mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-10 06:39:01 +02:00
ae6dec9dcb
Revert "[web] Convert models and self-referential test files to ESM " GitOrigin-RevId: 5455cccbb513bd9ca36ce526ff1553065f83d233
78 lines
1.8 KiB
JavaScript
78 lines
1.8 KiB
JavaScript
import OnboardingDataCollectionModel from '../../models/OnboardingDataCollection.js'
|
|
import OError from '@overleaf/o-error'
|
|
|
|
const { OnboardingDataCollection, OnboardingDataCollectionSchema } =
|
|
OnboardingDataCollectionModel
|
|
|
|
async function getOnboardingDataCollection(userId, projection = {}) {
|
|
try {
|
|
return await OnboardingDataCollection.findOne(
|
|
{ _id: userId },
|
|
projection
|
|
).exec()
|
|
} catch (error) {
|
|
throw OError.tag(error, 'Failed to get OnboardingDataCollection')
|
|
}
|
|
}
|
|
|
|
async function getOnboardingDataValue(userId, key) {
|
|
if (!OnboardingDataCollectionSchema.paths[key]) {
|
|
throw new Error(`${key} is not a valid onboarding data key`)
|
|
}
|
|
|
|
const result = await getOnboardingDataCollection(userId, { [key]: 1 })
|
|
return result ? result[key] : null
|
|
}
|
|
|
|
async function upsertOnboardingDataCollection({
|
|
userId,
|
|
firstName,
|
|
lastName,
|
|
usedLatex,
|
|
primaryOccupation,
|
|
companyDivisionDepartment,
|
|
companyJobTitle,
|
|
governmentJobTitle,
|
|
institutionName,
|
|
otherJobTitle,
|
|
nonprofitDivisionDepartment,
|
|
nonprofitJobTitle,
|
|
role,
|
|
subjectArea,
|
|
updatedAt,
|
|
}) {
|
|
const odc = await OnboardingDataCollection.findOneAndUpdate(
|
|
{ _id: userId },
|
|
{
|
|
firstName,
|
|
lastName,
|
|
usedLatex,
|
|
primaryOccupation,
|
|
companyDivisionDepartment,
|
|
companyJobTitle,
|
|
governmentJobTitle,
|
|
institutionName,
|
|
otherJobTitle,
|
|
nonprofitDivisionDepartment,
|
|
nonprofitJobTitle,
|
|
role,
|
|
subjectArea,
|
|
updatedAt,
|
|
},
|
|
{ upsert: true }
|
|
)
|
|
|
|
return odc
|
|
}
|
|
|
|
function deleteOnboardingDataCollection(id) {
|
|
return OnboardingDataCollection.deleteOne({ _id: id })
|
|
}
|
|
|
|
export default {
|
|
getOnboardingDataCollection,
|
|
upsertOnboardingDataCollection,
|
|
deleteOnboardingDataCollection,
|
|
getOnboardingDataValue,
|
|
}
|