Display a customized response
Last updated
Last updated
module.exports = (sequelize, DataTypes) => {
const { Sequelize } = sequelize;
const Companies = sequelize.define('companies', {
name: {
type: DataTypes.STRING,
},
status: {
type: DataTypes.STRING,
}
}, {
tableName: 'companies',
timestamps: false,
schema: process.env.DATABASE_SCHEMA,
});
return Companies;
};const { collection } = require('forest-express-sequelize');
collection('companies', {
actions: [{
name: 'Mark as Live',
type: 'bulk',
}],
});//...
const { RecordsGetter } = require('forest-express-sequelize');
router.post('/actions/mark-as-live', (req, res) => {
return new RecordsGetter(companies, req.user, req.query).getIdsFromRequest(req)
.then((companyIds) => {
const companiesCount = companyIds.length;
return companies
.update({ status: 'live' }, { where: { id: companyIds }})
.then(() => {
const message = companiesCount > 1 ? 'Companies are now live!' : 'Company is now live!';
res.send({ success: message });
});
});
});
//...