minor in sorting collection

This commit is contained in:
lesion 2024-08-21 10:46:23 +02:00
parent d773db650f
commit be638ee40a
No known key found for this signature in database
GPG key ID: 352918250B012177
2 changed files with 5 additions and 3 deletions

View file

@ -221,14 +221,14 @@ const collectionController = {
const collectionDetail = {
name: req.body.name,
isActor: true,
isTop: true
isTop: true,
sortIndex: Sequelize.literal(`(SELECT MAX(${Col('collections.sortIndex')})+1 from collections)`)
}
// TODO: validation
log.info(`Create collection: ${req.body.name}`)
try {
const collection = await Collection.create(collectionDetail)
await collection.update({ sortIndex: collection.id })
res.json(collection)
} catch (e) {
log.error(`Create collection failed ${e}`)

View file

@ -1,4 +1,5 @@
'use strict';
const Collection = require('../api/models/collection')
/** @type {import('sequelize-cli').Migration} */
module.exports = {
@ -6,7 +7,8 @@ module.exports = {
const transaction = await queryInterface.sequelize.transaction()
try {
await queryInterface.addColumn('collections', 'sortIndex', { type: Sequelize.INTEGER })
await queryInterface.sequelize.query('UPDATE collections set sortIndex=id')
const collection = Collection(queryInterface.sequelize, Sequelize.DataTypes)
await collection.update({ sortIndex: Sequelize.col('id')}, { where: {}, transaction })
return transaction.commit()
} catch (e) {
if (transaction) {