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 = {
|
const collectionDetail = {
|
||||||
name: req.body.name,
|
name: req.body.name,
|
||||||
isActor: true,
|
isActor: true,
|
||||||
isTop: true
|
isTop: true,
|
||||||
|
sortIndex: Sequelize.literal(`(SELECT MAX(${Col('collections.sortIndex')})+1 from collections)`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: validation
|
// TODO: validation
|
||||||
log.info(`Create collection: ${req.body.name}`)
|
log.info(`Create collection: ${req.body.name}`)
|
||||||
try {
|
try {
|
||||||
const collection = await Collection.create(collectionDetail)
|
const collection = await Collection.create(collectionDetail)
|
||||||
await collection.update({ sortIndex: collection.id })
|
|
||||||
res.json(collection)
|
res.json(collection)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log.error(`Create collection failed ${e}`)
|
log.error(`Create collection failed ${e}`)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
const Collection = require('../api/models/collection')
|
||||||
|
|
||||||
/** @type {import('sequelize-cli').Migration} */
|
/** @type {import('sequelize-cli').Migration} */
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -6,7 +7,8 @@ module.exports = {
|
||||||
const transaction = await queryInterface.sequelize.transaction()
|
const transaction = await queryInterface.sequelize.transaction()
|
||||||
try {
|
try {
|
||||||
await queryInterface.addColumn('collections', 'sortIndex', { type: Sequelize.INTEGER })
|
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()
|
return transaction.commit()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (transaction) {
|
if (transaction) {
|
||||||
|
|
Loading…
Reference in a new issue