This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const { Context } = require('../models');
|
||||
const { Context, Vocab } = require('../models');
|
||||
|
||||
/**
|
||||
* Context Controller - Workflow-based status management
|
||||
@@ -220,6 +220,28 @@ class ContextController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bulk update all status 2 to status 3 (Prompt Ready -> Generating)
|
||||
*/
|
||||
async bulkUpdateStatus2To3(req, res, next) {
|
||||
try {
|
||||
const [affectedCount] = await Context.update(
|
||||
{ status: 3 },
|
||||
{ where: { status: 2 } }
|
||||
);
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
message: `Updated ${affectedCount} context(s) from status 2 to status 3`,
|
||||
data: {
|
||||
affectedCount
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add images - Status 3 -> 4 (Image Ready)
|
||||
*/
|
||||
@@ -286,9 +308,28 @@ class ContextController {
|
||||
message: 'Context must be in Image Ready status (4) to approve'
|
||||
});
|
||||
}
|
||||
|
||||
await context.update({ status: 5 });
|
||||
|
||||
// add image to Vocab Image
|
||||
const currentVocab = await Vocab.findOne({ where: { vocab_id: context.reference_id } });
|
||||
console.log('Current Vocab:', currentVocab);
|
||||
if (currentVocab) {
|
||||
if (context.type_image === 'small') {
|
||||
const updatedImagesSmall = currentVocab.image_small || [];
|
||||
updatedImagesSmall.push(context.image);
|
||||
await currentVocab.update({ image_small: updatedImagesSmall });
|
||||
} else if (context.type_image === 'square') {
|
||||
const updatedImagesSquare = currentVocab.image_square || [];
|
||||
updatedImagesSquare.push(context.image);
|
||||
await currentVocab.update({ image_square: updatedImagesSquare });
|
||||
} else if (context.type_image === 'normal') {
|
||||
const updatedImagesNormal = currentVocab.image_normal || [];
|
||||
updatedImagesNormal.push(context.image);
|
||||
await currentVocab.update({ image_normal: updatedImagesNormal });
|
||||
}
|
||||
await currentVocab.save();
|
||||
}
|
||||
await context.update({
|
||||
status: 5
|
||||
});
|
||||
res.json({
|
||||
success: true,
|
||||
message: 'Context approved successfully',
|
||||
|
||||
@@ -96,8 +96,7 @@ exports.getAllStories = async (req, res) => {
|
||||
where,
|
||||
limit: parseInt(limit),
|
||||
offset,
|
||||
order: [[sort_by, sort_order.toUpperCase()]],
|
||||
attributes: ['id', 'name', 'logo', 'grade', 'tag', 'created_at', 'updated_at']
|
||||
order: [[sort_by, sort_order.toUpperCase()]]
|
||||
});
|
||||
|
||||
res.json({
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user