Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 1x 1x 363x 337x 337x 1x | 'use strict';
const { LexoRank } = require('lexorank');
class LexoRankTrait {
register(Model, customOptions) {
Model.addHook('beforeSave', async (modelInstance) => {
if (!modelInstance[Model.orderColumn]) {
const maxRank = await Model.query().getMax(Model.orderColumn);
modelInstance[Model.orderColumn] = maxRank
? LexoRank.parse(maxRank).genNext().toString()
: LexoRank.middle().toString();
}
});
}
}
module.exports = LexoRankTrait;
|