mirror of
https://framagit.org/les/gancio.git
synced 2025-01-31 16:42:22 +01:00
minor in sorting collection
This commit is contained in:
parent
d773db650f
commit
be638ee40a
2 changed files with 5 additions and 3 deletions
|
@ -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}`)
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue