Revert "changes to implement instructions"
This reverts commit 916fe7ace3.
This commit is contained in:
@@ -1,132 +0,0 @@
|
|||||||
const assert = require('node:assert/strict')
|
|
||||||
const { test } = require('node:test')
|
|
||||||
|
|
||||||
const userId = '507f1f77bcf86cd799439011'
|
|
||||||
const otherUserId = '507f191e810c19729de860ea'
|
|
||||||
const { requireDocumentId, requireUserId } = require('../worker-tenant')
|
|
||||||
|
|
||||||
test('queue IDs reject missing values and MongoDB query operators', () => {
|
|
||||||
assert.equal(requireUserId(userId), userId)
|
|
||||||
assert.equal(requireDocumentId(otherUserId), otherUserId)
|
|
||||||
assert.throws(() => requireUserId({ $ne: otherUserId }), /userId/)
|
|
||||||
assert.throws(() => requireDocumentId(undefined), /document ID/)
|
|
||||||
})
|
|
||||||
|
|
||||||
const factories = [
|
|
||||||
require('../voice-cloning-job-handler/voice_cloning/voice_cloning_service'),
|
|
||||||
require('../voice-cloning-job-handler/user_audio_profile/user_audio_profile_service'),
|
|
||||||
require('../voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service'),
|
|
||||||
require('../voice-synthsizer-job-handler/job/job_service'),
|
|
||||||
]
|
|
||||||
|
|
||||||
for (const [index, factory] of factories.entries()) {
|
|
||||||
test(`worker service ${index} scopes reads and writes`, async () => {
|
|
||||||
const calls = []
|
|
||||||
class Model {
|
|
||||||
static async findOne(filter) { calls.push(['findOne', filter]) }
|
|
||||||
static async find(filter) { calls.push(['find', filter]); return [] }
|
|
||||||
static async findOneAndUpdate(filter, update) {
|
|
||||||
calls.push(['findOneAndUpdate', filter, update])
|
|
||||||
}
|
|
||||||
static async updateMany(filter, update) {
|
|
||||||
calls.push(['updateMany', filter, update])
|
|
||||||
}
|
|
||||||
static async insertMany(data) { calls.push(['insertMany', data]) }
|
|
||||||
}
|
|
||||||
const service = factory(Model)
|
|
||||||
|
|
||||||
await service.read({ _id: 'record', userId })
|
|
||||||
await service.find({ userId })
|
|
||||||
await service.update({ _id: 'record', userId, status: 'completed' })
|
|
||||||
await service.remove({ _id: 'record', userId })
|
|
||||||
await service.removeMany({ userId })
|
|
||||||
await service.insertMany([{ userId, status: 'created' }])
|
|
||||||
|
|
||||||
for (const call of calls.slice(0, 5)) {
|
|
||||||
assert.equal(call[1].userId, userId)
|
|
||||||
}
|
|
||||||
assert.equal(calls[2][1].deleted, false)
|
|
||||||
assert.deepEqual(calls[2][2], { $set: { status: 'completed' } })
|
|
||||||
assert.equal(calls[5][1][0].userId, userId)
|
|
||||||
|
|
||||||
const originalLog = console.log
|
|
||||||
const before = calls.length
|
|
||||||
console.log = () => {}
|
|
||||||
try {
|
|
||||||
await assert.rejects(service.read({ _id: 'record' }), /userId/)
|
|
||||||
await assert.rejects(
|
|
||||||
service.update({ _id: 'record', userId: { $ne: otherUserId } }),
|
|
||||||
/userId/
|
|
||||||
)
|
|
||||||
await assert.rejects(service.remove({ _id: 'record' }), /userId/)
|
|
||||||
await assert.rejects(
|
|
||||||
service.insertMany([{ userId }, { status: 'created' }]),
|
|
||||||
/userId/
|
|
||||||
)
|
|
||||||
} finally {
|
|
||||||
console.log = originalLog
|
|
||||||
}
|
|
||||||
assert.equal(calls.length, before)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
test('salutation upsert stays within the job tenant', async () => {
|
|
||||||
const calls = []
|
|
||||||
class Model {
|
|
||||||
constructor(data) { calls.push(['create', data]) }
|
|
||||||
async save() { return this }
|
|
||||||
static async findOne(filter) { calls.push(['findOne', filter]); return null }
|
|
||||||
}
|
|
||||||
const service = require('../voice-synthsizer-job-handler/salutation/salutation_service')(Model)
|
|
||||||
await service.updateOrCreate({
|
|
||||||
firstName: 'Ada',
|
|
||||||
salutationVideo: 'url',
|
|
||||||
userAudioProfileId: 'profile',
|
|
||||||
}, userId)
|
|
||||||
assert.equal(calls[0][1].userId, userId)
|
|
||||||
assert.equal(calls[0][1].deleted, false)
|
|
||||||
assert.equal(calls[1][1].userId, userId)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('salutation upsert updates an existing record within the job tenant', async () => {
|
|
||||||
const calls = []
|
|
||||||
class Model {
|
|
||||||
static async findOne(filter) {
|
|
||||||
calls.push(['findOne', filter])
|
|
||||||
return { _id: 'salutation', userId }
|
|
||||||
}
|
|
||||||
static async findOneAndUpdate(filter, update) {
|
|
||||||
calls.push(['findOneAndUpdate', filter, update])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const service = require('../voice-synthsizer-job-handler/salutation/salutation_service')(Model)
|
|
||||||
await service.updateOrCreate({
|
|
||||||
firstName: 'Ada',
|
|
||||||
salutationVideo: 'url',
|
|
||||||
userAudioProfileId: 'profile',
|
|
||||||
}, userId)
|
|
||||||
assert.equal(calls[0][1].userId, userId)
|
|
||||||
assert.deepEqual(calls[1][1], { _id: 'salutation', userId, deleted: false })
|
|
||||||
assert.deepEqual(calls[1][2], { $set: { salutationVideo: 'url' } })
|
|
||||||
})
|
|
||||||
|
|
||||||
test('salutation updates cannot change ownership', async () => {
|
|
||||||
const calls = []
|
|
||||||
class Model {
|
|
||||||
static async findOneAndUpdate(filter, update) {
|
|
||||||
calls.push([filter, update])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const service = require('../voice-synthsizer-job-handler/salutation/salutation_service')(Model)
|
|
||||||
await service.update({
|
|
||||||
_id: 'salutation',
|
|
||||||
userId: otherUserId,
|
|
||||||
salutationVideo: 'url',
|
|
||||||
}, userId)
|
|
||||||
assert.deepEqual(calls[0], [
|
|
||||||
{ _id: 'salutation', userId, deleted: false },
|
|
||||||
{ $set: { salutationVideo: 'url' } },
|
|
||||||
])
|
|
||||||
await assert.rejects(service.modify({ _id: 'salutation' }), /userId/)
|
|
||||||
assert.equal(calls.length, 1)
|
|
||||||
})
|
|
||||||
@@ -10,7 +10,6 @@ const sqs = require('../app/services/sqs')
|
|||||||
const s3 = require('../app/services/s3')
|
const s3 = require('../app/services/s3')
|
||||||
const voiceCloningService = require('./voice_cloning')
|
const voiceCloningService = require('./voice_cloning')
|
||||||
const userAudioProfileService = require('./user_audio_profile')
|
const userAudioProfileService = require('./user_audio_profile')
|
||||||
const { requireUserId, requireDocumentId } = require('../worker-tenant')
|
|
||||||
|
|
||||||
AWS.config.update({ region: 'us-west-2' })
|
AWS.config.update({ region: 'us-west-2' })
|
||||||
const sqsQueueUrl = process.env.SQS_URL
|
const sqsQueueUrl = process.env.SQS_URL
|
||||||
@@ -102,15 +101,14 @@ const processQueue = () => {
|
|||||||
const receiptHandle = response.Messages[0].ReceiptHandle
|
const receiptHandle = response.Messages[0].ReceiptHandle
|
||||||
console.log('job===', job)
|
console.log('job===', job)
|
||||||
|
|
||||||
const { _id, userAudioProfileId, userId } = job._doc
|
const { metadata, input, _id, userAudioProfileId } = job._doc
|
||||||
requireUserId(userId)
|
|
||||||
requireDocumentId(_id)
|
|
||||||
requireDocumentId(userAudioProfileId)
|
|
||||||
console.log('userAudioProfileId', userAudioProfileId)
|
console.log('userAudioProfileId', userAudioProfileId)
|
||||||
console.log('_id', _id)
|
console.log('_id', _id)
|
||||||
const { env } = job
|
const { env } = job
|
||||||
console.log('env', env)
|
console.log('env', env)
|
||||||
|
|
||||||
|
console.log('metadata------', metadata)
|
||||||
|
console.log('input', input)
|
||||||
const DB_URI =
|
const DB_URI =
|
||||||
env === 'production'
|
env === 'production'
|
||||||
? mongoUriProd
|
? mongoUriProd
|
||||||
@@ -128,26 +126,9 @@ const processQueue = () => {
|
|||||||
? cloudFrontUrlStaging
|
? cloudFrontUrlStaging
|
||||||
: cloudFrontUrlDev
|
: cloudFrontUrlDev
|
||||||
|
|
||||||
let authorized = false
|
|
||||||
try {
|
try {
|
||||||
await sqs.deleteMessageFromSQS(sqsQueueUrl, receiptHandle)
|
await sqs.deleteMessageFromSQS(sqsQueueUrl, receiptHandle)
|
||||||
|
|
||||||
const cloningJob = await voiceCloningService.read({
|
|
||||||
_id,
|
|
||||||
userId,
|
|
||||||
userAudioProfileId,
|
|
||||||
})
|
|
||||||
const audioProfile = await userAudioProfileService.read({
|
|
||||||
_id: userAudioProfileId,
|
|
||||||
userId,
|
|
||||||
})
|
|
||||||
if (!cloningJob || !audioProfile) {
|
|
||||||
throw new Error('Cloning job or audio profile does not belong to user')
|
|
||||||
}
|
|
||||||
authorized = true
|
|
||||||
|
|
||||||
const { metadata, input } = cloningJob
|
|
||||||
|
|
||||||
const { directoryName } = metadata
|
const { directoryName } = metadata
|
||||||
console.log('directoryName', directoryName)
|
console.log('directoryName', directoryName)
|
||||||
const logPath = `/mnt/efs/potion-voice/${env}/${directoryName}`
|
const logPath = `/mnt/efs/potion-voice/${env}/${directoryName}`
|
||||||
@@ -155,10 +136,9 @@ const processQueue = () => {
|
|||||||
fs.mkdirSync(logPath, { recursive: true })
|
fs.mkdirSync(logPath, { recursive: true })
|
||||||
}
|
}
|
||||||
// update the db model to processing
|
// update the db model to processing
|
||||||
await voiceCloningService.update({ _id, userId, status: 'processing' })
|
await voiceCloningService.update({ _id, status: 'processing' })
|
||||||
await userAudioProfileService.update({
|
await userAudioProfileService.update({
|
||||||
_id: userAudioProfileId,
|
_id: userAudioProfileId,
|
||||||
userId,
|
|
||||||
status: 'processing',
|
status: 'processing',
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -260,7 +240,7 @@ const processQueue = () => {
|
|||||||
console.timeEnd(VOICE_MINIMIZE_LABEL)
|
console.timeEnd(VOICE_MINIMIZE_LABEL)
|
||||||
|
|
||||||
// Add the code to update location of generated model and status into DB
|
// Add the code to update location of generated model and status into DB
|
||||||
await voiceCloningService.update({ _id, userId, status: 'completed' })
|
await voiceCloningService.update({ _id, status: 'completed' })
|
||||||
|
|
||||||
const training_model_path = {
|
const training_model_path = {
|
||||||
voice_model_path: `${resultsPath}/${generatedDirectoryName}/checkpoint_365200.pth`,
|
voice_model_path: `${resultsPath}/${generatedDirectoryName}/checkpoint_365200.pth`,
|
||||||
@@ -272,7 +252,6 @@ const processQueue = () => {
|
|||||||
|
|
||||||
await userAudioProfileService.update({
|
await userAudioProfileService.update({
|
||||||
_id: userAudioProfileId,
|
_id: userAudioProfileId,
|
||||||
userId,
|
|
||||||
status: 'completed',
|
status: 'completed',
|
||||||
training_model_path,
|
training_model_path,
|
||||||
})
|
})
|
||||||
@@ -294,7 +273,6 @@ const processQueue = () => {
|
|||||||
// add S3 path to user audio profile model
|
// add S3 path to user audio profile model
|
||||||
await userAudioProfileService.update({
|
await userAudioProfileService.update({
|
||||||
_id: userAudioProfileId,
|
_id: userAudioProfileId,
|
||||||
userId,
|
|
||||||
training_model_s3_path,
|
training_model_s3_path,
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -307,14 +285,11 @@ const processQueue = () => {
|
|||||||
Bugsnag.notify(error)
|
Bugsnag.notify(error)
|
||||||
|
|
||||||
// update the db to set status as error
|
// update the db to set status as error
|
||||||
if (authorized) {
|
await voiceCloningService.update({ _id, status: 'error' })
|
||||||
await voiceCloningService.update({ _id, userId, status: 'error' })
|
|
||||||
await userAudioProfileService.update({
|
await userAudioProfileService.update({
|
||||||
_id: userAudioProfileId,
|
_id: userAudioProfileId,
|
||||||
userId,
|
|
||||||
status: 'error',
|
status: 'error',
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
resolve() // to continue working on new jobs
|
resolve() // to continue working on new jobs
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
const { requireUserId } = require('../../worker-tenant')
|
|
||||||
const StringifyUtils = require('../../app/services/utils/logService')
|
const StringifyUtils = require('../../app/services/utils/logService')
|
||||||
|
|
||||||
const create = (UserAudioProfileModel) => async (data) => {
|
const create = (UserAudioProfileModel) => async (data) => {
|
||||||
try {
|
try {
|
||||||
const newModel = new UserAudioProfileModel({ ...data, userId: requireUserId(data.userId) })
|
const newModel = new UserAudioProfileModel({ ...data })
|
||||||
const savedModel = await newModel.save()
|
const savedModel = await newModel.save()
|
||||||
return savedModel
|
return savedModel
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -18,9 +17,7 @@ const create = (UserAudioProfileModel) => async (data) => {
|
|||||||
|
|
||||||
const insertMany = (UserAudioProfileModel) => async (data) => {
|
const insertMany = (UserAudioProfileModel) => async (data) => {
|
||||||
try {
|
try {
|
||||||
const inserted = await UserAudioProfileModel.insertMany(
|
const inserted = await UserAudioProfileModel.insertMany(data)
|
||||||
data.map((item) => ({ ...item, userId: requireUserId(item.userId) }))
|
|
||||||
)
|
|
||||||
return inserted
|
return inserted
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const details = { data }
|
const details = { data }
|
||||||
@@ -36,7 +33,6 @@ const read = (UserAudioProfileModel) => async (filter) => {
|
|||||||
try {
|
try {
|
||||||
const foundModel = await UserAudioProfileModel.findOne({
|
const foundModel = await UserAudioProfileModel.findOne({
|
||||||
...filter,
|
...filter,
|
||||||
userId: requireUserId(filter.userId),
|
|
||||||
deleted: false,
|
deleted: false,
|
||||||
})
|
})
|
||||||
return foundModel
|
return foundModel
|
||||||
@@ -54,7 +50,6 @@ const find = (UserAudioProfileModel) => async (filter) => {
|
|||||||
try {
|
try {
|
||||||
const foundModels = await UserAudioProfileModel.find({
|
const foundModels = await UserAudioProfileModel.find({
|
||||||
...filter,
|
...filter,
|
||||||
userId: requireUserId(filter.userId),
|
|
||||||
deleted: false,
|
deleted: false,
|
||||||
})
|
})
|
||||||
return foundModels
|
return foundModels
|
||||||
@@ -70,11 +65,12 @@ const find = (UserAudioProfileModel) => async (filter) => {
|
|||||||
|
|
||||||
const update = (UserAudioProfileModel) => async (data) => {
|
const update = (UserAudioProfileModel) => async (data) => {
|
||||||
try {
|
try {
|
||||||
const { _id, userId, ...changes } = data
|
|
||||||
const updatedModel = await UserAudioProfileModel.findOneAndUpdate(
|
const updatedModel = await UserAudioProfileModel.findOneAndUpdate(
|
||||||
{ _id, userId: requireUserId(userId), deleted: false },
|
{ _id: data._id },
|
||||||
{ $set: changes },
|
data,
|
||||||
{ new: true }
|
{
|
||||||
|
new: true,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
return updatedModel
|
return updatedModel
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -90,7 +86,7 @@ const update = (UserAudioProfileModel) => async (data) => {
|
|||||||
const remove = (UserAudioProfileModel) => async (filter) => {
|
const remove = (UserAudioProfileModel) => async (filter) => {
|
||||||
try {
|
try {
|
||||||
const updatedModel = await UserAudioProfileModel.findOneAndUpdate(
|
const updatedModel = await UserAudioProfileModel.findOneAndUpdate(
|
||||||
{ ...filter, userId: requireUserId(filter.userId) },
|
{ ...filter },
|
||||||
{
|
{
|
||||||
$set: {
|
$set: {
|
||||||
deleted: true,
|
deleted: true,
|
||||||
@@ -112,7 +108,7 @@ const remove = (UserAudioProfileModel) => async (filter) => {
|
|||||||
const removeMany = (UserAudioProfileModel) => async (filter) => {
|
const removeMany = (UserAudioProfileModel) => async (filter) => {
|
||||||
try {
|
try {
|
||||||
const updatedModel = await UserAudioProfileModel.updateMany(
|
const updatedModel = await UserAudioProfileModel.updateMany(
|
||||||
{ ...filter, userId: requireUserId(filter.userId) },
|
{ ...filter },
|
||||||
{
|
{
|
||||||
$set: {
|
$set: {
|
||||||
deleted: true,
|
deleted: true,
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
const { requireUserId } = require('../../worker-tenant')
|
|
||||||
const StringifyUtils = require('../../app/services/utils/logService')
|
const StringifyUtils = require('../../app/services/utils/logService')
|
||||||
|
|
||||||
const create = (VoiceCloningModel) => async (data) => {
|
const create = (VoiceCloningModel) => async (data) => {
|
||||||
try {
|
try {
|
||||||
const newModel = new VoiceCloningModel({ ...data, userId: requireUserId(data.userId) })
|
const newModel = new VoiceCloningModel({ ...data })
|
||||||
const savedModel = await newModel.save()
|
const savedModel = await newModel.save()
|
||||||
return savedModel
|
return savedModel
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -18,9 +17,7 @@ const create = (VoiceCloningModel) => async (data) => {
|
|||||||
|
|
||||||
const insertMany = (VoiceCloningModel) => async (data) => {
|
const insertMany = (VoiceCloningModel) => async (data) => {
|
||||||
try {
|
try {
|
||||||
const inserted = await VoiceCloningModel.insertMany(
|
const inserted = await VoiceCloningModel.insertMany(data)
|
||||||
data.map((item) => ({ ...item, userId: requireUserId(item.userId) }))
|
|
||||||
)
|
|
||||||
return inserted
|
return inserted
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const details = { data }
|
const details = { data }
|
||||||
@@ -36,7 +33,6 @@ const read = (VoiceCloningModel) => async (filter) => {
|
|||||||
try {
|
try {
|
||||||
const foundModel = await VoiceCloningModel.findOne({
|
const foundModel = await VoiceCloningModel.findOne({
|
||||||
...filter,
|
...filter,
|
||||||
userId: requireUserId(filter.userId),
|
|
||||||
deleted: false,
|
deleted: false,
|
||||||
})
|
})
|
||||||
return foundModel
|
return foundModel
|
||||||
@@ -54,7 +50,6 @@ const find = (VoiceCloningModel) => async (filter) => {
|
|||||||
try {
|
try {
|
||||||
const foundModels = await VoiceCloningModel.find({
|
const foundModels = await VoiceCloningModel.find({
|
||||||
...filter,
|
...filter,
|
||||||
userId: requireUserId(filter.userId),
|
|
||||||
deleted: false,
|
deleted: false,
|
||||||
})
|
})
|
||||||
return foundModels
|
return foundModels
|
||||||
@@ -70,11 +65,12 @@ const find = (VoiceCloningModel) => async (filter) => {
|
|||||||
|
|
||||||
const update = (VoiceCloningModel) => async (data) => {
|
const update = (VoiceCloningModel) => async (data) => {
|
||||||
try {
|
try {
|
||||||
const { _id, userId, ...changes } = data
|
|
||||||
const updatedModel = await VoiceCloningModel.findOneAndUpdate(
|
const updatedModel = await VoiceCloningModel.findOneAndUpdate(
|
||||||
{ _id, userId: requireUserId(userId), deleted: false },
|
{ _id: data._id },
|
||||||
{ $set: changes },
|
data,
|
||||||
{ new: true }
|
{
|
||||||
|
new: true,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
return updatedModel
|
return updatedModel
|
||||||
@@ -91,7 +87,7 @@ const update = (VoiceCloningModel) => async (data) => {
|
|||||||
const remove = (VoiceCloningModel) => async (filter) => {
|
const remove = (VoiceCloningModel) => async (filter) => {
|
||||||
try {
|
try {
|
||||||
const updatedModel = await VoiceCloningModel.findOneAndUpdate(
|
const updatedModel = await VoiceCloningModel.findOneAndUpdate(
|
||||||
{ ...filter, userId: requireUserId(filter.userId) },
|
{ ...filter },
|
||||||
{
|
{
|
||||||
$set: {
|
$set: {
|
||||||
deleted: true,
|
deleted: true,
|
||||||
@@ -113,7 +109,7 @@ const remove = (VoiceCloningModel) => async (filter) => {
|
|||||||
const removeMany = (VoiceCloningModel) => async (filter) => {
|
const removeMany = (VoiceCloningModel) => async (filter) => {
|
||||||
try {
|
try {
|
||||||
const updatedModel = await VoiceCloningModel.updateMany(
|
const updatedModel = await VoiceCloningModel.updateMany(
|
||||||
{ ...filter, userId: requireUserId(filter.userId) },
|
{ ...filter },
|
||||||
{
|
{
|
||||||
$set: {
|
$set: {
|
||||||
deleted: true,
|
deleted: true,
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ const recordingModel = require('./recording')
|
|||||||
const recordingSalutationModel = require('./recording_salutation')
|
const recordingSalutationModel = require('./recording_salutation')
|
||||||
const jobService = require('./job')
|
const jobService = require('./job')
|
||||||
const salutationService = require('./salutation')
|
const salutationService = require('./salutation')
|
||||||
const { requireUserId, requireDocumentId } = require('../worker-tenant')
|
|
||||||
let throttleMessageFetching = true
|
let throttleMessageFetching = true
|
||||||
AWS.config.update({ region: 'us-west-2' })
|
AWS.config.update({ region: 'us-west-2' })
|
||||||
const sqsQueueUrl = process.env.SQS_URL
|
const sqsQueueUrl = process.env.SQS_URL
|
||||||
@@ -80,14 +79,8 @@ const processQueue = () => {
|
|||||||
recordingId,
|
recordingId,
|
||||||
baseUrlForPotionAi,
|
baseUrlForPotionAi,
|
||||||
env,
|
env,
|
||||||
userId,
|
|
||||||
} = job
|
} = job
|
||||||
|
|
||||||
requireUserId(userId)
|
|
||||||
requireDocumentId(userAudioProfileId)
|
|
||||||
requireDocumentId(salutationId)
|
|
||||||
requireDocumentId(recordingId)
|
|
||||||
|
|
||||||
const DB_URI =
|
const DB_URI =
|
||||||
env === 'production'
|
env === 'production'
|
||||||
? mongoUriProd
|
? mongoUriProd
|
||||||
@@ -102,24 +95,10 @@ const processQueue = () => {
|
|||||||
|
|
||||||
const userAudioProfile = await userAudioProfileService.find({
|
const userAudioProfile = await userAudioProfileService.find({
|
||||||
_id: userAudioProfileId,
|
_id: userAudioProfileId,
|
||||||
userId,
|
|
||||||
status: 'completed',
|
status: 'completed',
|
||||||
})
|
})
|
||||||
if (userAudioProfile.length) {
|
if (userAudioProfile) {
|
||||||
const { training_model_path } = userAudioProfile[0]
|
const { training_model_path, userId } = userAudioProfile[0]
|
||||||
const salutationToUpdate = await recordingSalutationModel.findOne({
|
|
||||||
_id: salutationId,
|
|
||||||
userId,
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
const recordingToUpdate = await recordingModel.findOne({
|
|
||||||
_id: recordingId,
|
|
||||||
userId,
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
if (!salutationToUpdate || !recordingToUpdate) {
|
|
||||||
throw new Error('Job recording or salutation does not belong to user')
|
|
||||||
}
|
|
||||||
const {
|
const {
|
||||||
voice_model_light_path,
|
voice_model_light_path,
|
||||||
voice_model_config_light_path,
|
voice_model_config_light_path,
|
||||||
@@ -170,6 +149,16 @@ const processQueue = () => {
|
|||||||
userId
|
userId
|
||||||
)
|
)
|
||||||
// update the dynamic recordings for the current dynamic video with salutation url
|
// update the dynamic recordings for the current dynamic video with salutation url
|
||||||
|
const salutationToUpdate = await recordingSalutationModel.findOne({
|
||||||
|
_id: salutationId,
|
||||||
|
deleted: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
const recordingToUpdate = await recordingModel.findOne({
|
||||||
|
_id: recordingId,
|
||||||
|
deleted: false,
|
||||||
|
})
|
||||||
|
|
||||||
if (
|
if (
|
||||||
salutationToUpdate &&
|
salutationToUpdate &&
|
||||||
salutationToUpdate.deleted === false &&
|
salutationToUpdate.deleted === false &&
|
||||||
@@ -180,8 +169,6 @@ const processQueue = () => {
|
|||||||
await recordingSalutationModel.findOneAndUpdate(
|
await recordingSalutationModel.findOneAndUpdate(
|
||||||
{
|
{
|
||||||
_id: salutationId,
|
_id: salutationId,
|
||||||
userId,
|
|
||||||
deleted: false,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$set: {
|
$set: {
|
||||||
@@ -213,7 +200,7 @@ const processQueue = () => {
|
|||||||
jobsToInsert.push({
|
jobsToInsert.push({
|
||||||
firstName,
|
firstName,
|
||||||
recordingId: recordingToUpdate._id,
|
recordingId: recordingToUpdate._id,
|
||||||
userId,
|
userId: recordingToUpdate.userId,
|
||||||
salutationId: salutationToUpdate._id,
|
salutationId: salutationToUpdate._id,
|
||||||
metadata: jobData,
|
metadata: jobData,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
const { requireUserId } = require('../../worker-tenant')
|
|
||||||
const StringifyUtils = require('../../app/services/utils/logService')
|
const StringifyUtils = require('../../app/services/utils/logService')
|
||||||
|
|
||||||
const create = (Job) => async (jobData) => {
|
const create = (Job) => async (jobData) => {
|
||||||
try {
|
try {
|
||||||
const newJob = new Job({ ...jobData, userId: requireUserId(jobData.userId) })
|
const newJob = new Job({ ...jobData })
|
||||||
const savedJob = await newJob.save()
|
const savedJob = await newJob.save()
|
||||||
return savedJob
|
return savedJob
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -18,9 +17,7 @@ const create = (Job) => async (jobData) => {
|
|||||||
|
|
||||||
const insertMany = (Job) => async (jobData) => {
|
const insertMany = (Job) => async (jobData) => {
|
||||||
try {
|
try {
|
||||||
const inserted = await Job.insertMany(
|
const inserted = await Job.insertMany(jobData)
|
||||||
jobData.map((item) => ({ ...item, userId: requireUserId(item.userId) }))
|
|
||||||
)
|
|
||||||
return inserted
|
return inserted
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const details = { jobData }
|
const details = { jobData }
|
||||||
@@ -36,7 +33,6 @@ const read = (Job) => async (filter) => {
|
|||||||
try {
|
try {
|
||||||
const foundJob = await Job.findOne({
|
const foundJob = await Job.findOne({
|
||||||
...filter,
|
...filter,
|
||||||
userId: requireUserId(filter.userId),
|
|
||||||
deleted: false,
|
deleted: false,
|
||||||
})
|
})
|
||||||
return foundJob
|
return foundJob
|
||||||
@@ -54,7 +50,6 @@ const find = (Job) => async (filter) => {
|
|||||||
try {
|
try {
|
||||||
const foundJobs = await Job.find({
|
const foundJobs = await Job.find({
|
||||||
...filter,
|
...filter,
|
||||||
userId: requireUserId(filter.userId),
|
|
||||||
deleted: false,
|
deleted: false,
|
||||||
})
|
})
|
||||||
return foundJobs
|
return foundJobs
|
||||||
@@ -70,12 +65,9 @@ const find = (Job) => async (filter) => {
|
|||||||
|
|
||||||
const update = (Job) => async (job) => {
|
const update = (Job) => async (job) => {
|
||||||
try {
|
try {
|
||||||
const { _id, userId, ...changes } = job
|
const updatedJob = await Job.findOneAndUpdate({ _id: job._id }, job, {
|
||||||
const updatedJob = await Job.findOneAndUpdate(
|
new: true,
|
||||||
{ _id, userId: requireUserId(userId), deleted: false },
|
})
|
||||||
{ $set: changes },
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedJob
|
return updatedJob
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const details = { job }
|
const details = { job }
|
||||||
@@ -90,7 +82,7 @@ const update = (Job) => async (job) => {
|
|||||||
const remove = (Job) => async (filter) => {
|
const remove = (Job) => async (filter) => {
|
||||||
try {
|
try {
|
||||||
const updatedJob = await Job.findOneAndUpdate(
|
const updatedJob = await Job.findOneAndUpdate(
|
||||||
{ ...filter, userId: requireUserId(filter.userId) },
|
{ ...filter },
|
||||||
{
|
{
|
||||||
$set: {
|
$set: {
|
||||||
deleted: true,
|
deleted: true,
|
||||||
@@ -112,7 +104,7 @@ const remove = (Job) => async (filter) => {
|
|||||||
const removeMany = (Job) => async (filter) => {
|
const removeMany = (Job) => async (filter) => {
|
||||||
try {
|
try {
|
||||||
const updatedJob = await Job.updateMany(
|
const updatedJob = await Job.updateMany(
|
||||||
{ ...filter, userId: requireUserId(filter.userId) },
|
{ ...filter },
|
||||||
{
|
{
|
||||||
$set: {
|
$set: {
|
||||||
deleted: true,
|
deleted: true,
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
const { requireUserId } = require('../../worker-tenant')
|
|
||||||
|
|
||||||
const create = (Salutation) => async (salutationData, userId) => {
|
const create = (Salutation) => async (salutationData, userId) => {
|
||||||
const newSalutation = new Salutation({ ...salutationData, userId: requireUserId(userId) })
|
const newSalutation = new Salutation({ ...salutationData, userId })
|
||||||
const savedSalutation = await newSalutation.save()
|
const savedSalutation = await newSalutation.save()
|
||||||
return savedSalutation
|
return savedSalutation
|
||||||
}
|
}
|
||||||
@@ -9,7 +7,6 @@ const create = (Salutation) => async (salutationData, userId) => {
|
|||||||
const read = (Salutation) => async (filter) => {
|
const read = (Salutation) => async (filter) => {
|
||||||
const foundSalutation = await Salutation.findOne({
|
const foundSalutation = await Salutation.findOne({
|
||||||
...filter,
|
...filter,
|
||||||
userId: requireUserId(filter.userId),
|
|
||||||
deleted: false,
|
deleted: false,
|
||||||
})
|
})
|
||||||
return foundSalutation
|
return foundSalutation
|
||||||
@@ -18,34 +15,28 @@ const read = (Salutation) => async (filter) => {
|
|||||||
const find = (Salutation) => async (filter) => {
|
const find = (Salutation) => async (filter) => {
|
||||||
const foundSalutations = await Salutation.find({
|
const foundSalutations = await Salutation.find({
|
||||||
...filter,
|
...filter,
|
||||||
userId: requireUserId(filter.userId),
|
|
||||||
deleted: false,
|
deleted: false,
|
||||||
})
|
})
|
||||||
return foundSalutations
|
return foundSalutations
|
||||||
}
|
}
|
||||||
|
|
||||||
const update = (Salutation) => async (salutation, userId) => {
|
const update = (Salutation) => async (salutation, userId) => {
|
||||||
const { _id, ...changes } = salutation
|
|
||||||
delete changes.userId
|
|
||||||
const updatedSalutation = await Salutation.findOneAndUpdate(
|
const updatedSalutation = await Salutation.findOneAndUpdate(
|
||||||
{ _id, userId: requireUserId(userId), deleted: false },
|
{ _id: salutation._id, userId },
|
||||||
{ $set: changes },
|
salutation,
|
||||||
{ new: true }
|
{ new: true }
|
||||||
)
|
)
|
||||||
return updatedSalutation
|
return updatedSalutation
|
||||||
}
|
}
|
||||||
|
|
||||||
const modify = (Salutation) => async (salutation, userId) => {
|
const modify = (Salutation) => async (salutation) => {
|
||||||
const findQuery = salutation._id
|
const findQuery = salutation._id
|
||||||
? { _id: salutation._id }
|
? { _id: salutation._id }
|
||||||
: { transcriptId: salutation.transcriptId }
|
: { transcriptId: salutation.transcriptId }
|
||||||
|
|
||||||
const changes = { ...salutation }
|
|
||||||
delete changes._id
|
|
||||||
delete changes.userId
|
|
||||||
const updatedSalutation = await Salutation.findOneAndUpdate(
|
const updatedSalutation = await Salutation.findOneAndUpdate(
|
||||||
{ ...findQuery, userId: requireUserId(userId), deleted: false },
|
findQuery,
|
||||||
{ $set: changes },
|
salutation,
|
||||||
{ new: true }
|
{ new: true }
|
||||||
)
|
)
|
||||||
return updatedSalutation
|
return updatedSalutation
|
||||||
@@ -60,10 +51,8 @@ const updateOrCreate =
|
|||||||
userId,
|
userId,
|
||||||
})
|
})
|
||||||
if (salutation) {
|
if (salutation) {
|
||||||
return await update(Salutation)(
|
salutation.salutationVideo = salutationVideo
|
||||||
{ _id: salutation._id, salutationVideo },
|
return await update(Salutation)(salutation, userId)
|
||||||
userId
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
return await create(Salutation)(
|
return await create(Salutation)(
|
||||||
{ firstName, salutationVideo, userAudioProfileId },
|
{ firstName, salutationVideo, userAudioProfileId },
|
||||||
@@ -74,7 +63,7 @@ const updateOrCreate =
|
|||||||
|
|
||||||
const remove = (Salutation) => async (filter, userId) => {
|
const remove = (Salutation) => async (filter, userId) => {
|
||||||
const updatedSalutation = await Salutation.findOneAndUpdate(
|
const updatedSalutation = await Salutation.findOneAndUpdate(
|
||||||
{ ...filter, userId: requireUserId(userId) },
|
{ ...filter, userId },
|
||||||
{
|
{
|
||||||
$set: {
|
$set: {
|
||||||
deleted: true,
|
deleted: true,
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
const { requireUserId } = require('../../worker-tenant')
|
|
||||||
const StringifyUtils = require('../../app/services/utils/logService')
|
const StringifyUtils = require('../../app/services/utils/logService')
|
||||||
|
|
||||||
const create = (UserAudioProfileModel) => async (data) => {
|
const create = (UserAudioProfileModel) => async (data) => {
|
||||||
try {
|
try {
|
||||||
const newModel = new UserAudioProfileModel({ ...data, userId: requireUserId(data.userId) })
|
const newModel = new UserAudioProfileModel({ ...data })
|
||||||
const savedModel = await newModel.save()
|
const savedModel = await newModel.save()
|
||||||
return savedModel
|
return savedModel
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -18,9 +17,7 @@ const create = (UserAudioProfileModel) => async (data) => {
|
|||||||
|
|
||||||
const insertMany = (UserAudioProfileModel) => async (data) => {
|
const insertMany = (UserAudioProfileModel) => async (data) => {
|
||||||
try {
|
try {
|
||||||
const inserted = await UserAudioProfileModel.insertMany(
|
const inserted = await UserAudioProfileModel.insertMany(data)
|
||||||
data.map((item) => ({ ...item, userId: requireUserId(item.userId) }))
|
|
||||||
)
|
|
||||||
return inserted
|
return inserted
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const details = { data }
|
const details = { data }
|
||||||
@@ -36,7 +33,6 @@ const read = (UserAudioProfileModel) => async (filter) => {
|
|||||||
try {
|
try {
|
||||||
const foundModel = await UserAudioProfileModel.findOne({
|
const foundModel = await UserAudioProfileModel.findOne({
|
||||||
...filter,
|
...filter,
|
||||||
userId: requireUserId(filter.userId),
|
|
||||||
deleted: false
|
deleted: false
|
||||||
})
|
})
|
||||||
return foundModel
|
return foundModel
|
||||||
@@ -54,7 +50,6 @@ const find = (UserAudioProfileModel) => async (filter) => {
|
|||||||
try {
|
try {
|
||||||
const foundModels = await UserAudioProfileModel.find({
|
const foundModels = await UserAudioProfileModel.find({
|
||||||
...filter,
|
...filter,
|
||||||
userId: requireUserId(filter.userId),
|
|
||||||
deleted: false
|
deleted: false
|
||||||
})
|
})
|
||||||
return foundModels
|
return foundModels
|
||||||
@@ -71,11 +66,12 @@ const find = (UserAudioProfileModel) => async (filter) => {
|
|||||||
const update = (UserAudioProfileModel) => async (data) => {
|
const update = (UserAudioProfileModel) => async (data) => {
|
||||||
console.log('ua data', data)
|
console.log('ua data', data)
|
||||||
try {
|
try {
|
||||||
const { _id, userId, ...changes } = data
|
|
||||||
const updatedModel = await UserAudioProfileModel.findOneAndUpdate(
|
const updatedModel = await UserAudioProfileModel.findOneAndUpdate(
|
||||||
{ _id, userId: requireUserId(userId), deleted: false },
|
{ _id: data._id },
|
||||||
{ $set: changes },
|
data,
|
||||||
{ new: true }
|
{
|
||||||
|
new: true
|
||||||
|
}
|
||||||
)
|
)
|
||||||
console.log('ua updatedModel', updatedModel)
|
console.log('ua updatedModel', updatedModel)
|
||||||
return updatedModel
|
return updatedModel
|
||||||
@@ -92,7 +88,7 @@ const update = (UserAudioProfileModel) => async (data) => {
|
|||||||
const remove = (UserAudioProfileModel) => async (filter) => {
|
const remove = (UserAudioProfileModel) => async (filter) => {
|
||||||
try {
|
try {
|
||||||
const updatedModel = await UserAudioProfileModel.findOneAndUpdate(
|
const updatedModel = await UserAudioProfileModel.findOneAndUpdate(
|
||||||
{ ...filter, userId: requireUserId(filter.userId) },
|
{ ...filter },
|
||||||
{
|
{
|
||||||
$set: {
|
$set: {
|
||||||
deleted: true
|
deleted: true
|
||||||
@@ -114,7 +110,7 @@ const remove = (UserAudioProfileModel) => async (filter) => {
|
|||||||
const removeMany = (UserAudioProfileModel) => async (filter) => {
|
const removeMany = (UserAudioProfileModel) => async (filter) => {
|
||||||
try {
|
try {
|
||||||
const updatedModel = await UserAudioProfileModel.updateMany(
|
const updatedModel = await UserAudioProfileModel.updateMany(
|
||||||
{ ...filter, userId: requireUserId(filter.userId) },
|
{ ...filter },
|
||||||
{
|
{
|
||||||
$set: {
|
$set: {
|
||||||
deleted: true
|
deleted: true
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
// SQS payloads must never turn a tenant or document filter into a broad query.
|
|
||||||
const requireId = (id, name) => {
|
|
||||||
if (typeof id !== 'string' || !/^[0-9a-f]{24}$/i.test(id)) {
|
|
||||||
throw new Error(`A valid ${name} is required`)
|
|
||||||
}
|
|
||||||
return id
|
|
||||||
}
|
|
||||||
|
|
||||||
const requireUserId = (userId) => requireId(userId, 'userId')
|
|
||||||
const requireDocumentId = (id) => requireId(id, 'document ID')
|
|
||||||
|
|
||||||
module.exports = { requireUserId, requireDocumentId }
|
|
||||||
Reference in New Issue
Block a user