update
All checks were successful
Deploy to Production / deploy (push) Successful in 20s

This commit is contained in:
silverpro89
2026-02-18 18:01:45 +07:00
parent 09e72e37e7
commit b7ba1d02b3
10 changed files with 1207 additions and 1248 deletions

View File

@@ -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',

View File

@@ -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