Dear @anon20071947,
// This model was generated by Lumber. However, you remain in control of your models.
// Learn how here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models
module.exports = (sequelize, DataTypes) => {
const { Sequelize } = sequelize;
// This section contains the fields of your model, mapped to your table’s columns.
// Learn more here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model
const Cdt = sequelize.define(‘cdt’, {
cdtId: {
type: DataTypes.INTEGER,
primaryKey: true,
allowNull: false,
autoIncrement: true,
},
cdtName: {
type: DataTypes.STRING,
allowNull: false,
},
cdtNameEn: {
type: DataTypes.STRING,
},
cdtCode: {
type: DataTypes.STRING,
allowNull: false,
},
cdtCodeLong: {
type: DataTypes.STRING,
},
cdtValidFrom: {
type: DataTypes.DATE,
},
cdtValidTo: {
type: DataTypes.DATE,
},
createdAt: {
type: DataTypes.DATE,
defaultValue: Sequelize.literal(‘CURRENT_TIMESTAMP’),
},
cdtStatus: {
type: DataTypes.STRING,
allowNull: false,
},
}, {
tableName: ‘cdt’,
underscored: true,
timestamps: false,
});
// This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
Cdt.associate = (models) => {
Cdt.belongsTo(models.user, {
foreignKey: {
name: ‘cdtOwnerKey’,
field: ‘cdt_owner’,
},
targetKey: ‘userId’,
as: ‘cdtOwner’,
});
Cdt.belongsTo(models.cdt, {
foreignKey: {
name: ‘cdtIdParentKey’,
field: ‘cdt_id_parent’,
},
targetKey: ‘cdtId’,
as: ‘cdtIdParent’,
});
Cdt.hasMany(models.cdt, {
foreignKey: {
name: ‘cdtIdParentKey’,
field: ‘cdt_id_parent’,
},
as: ‘cdtIdParentCdts’,
});
};
return Cdt;
};
const express = require(‘express’);
const { PermissionMiddlewareCreator, RecordsGetter } = require(‘forest-express-sequelize’);
const { cdt } = require(‘…/models’);
const router = express.Router();
const permissionMiddlewareCreator = new PermissionMiddlewareCreator(‘cdt’);
// This file contains the logic of every route in Forest Admin for the collection cdt:
// - Native routes are already generated but can be extended/overriden - Learn how to extend a route here: Extend a route - Developer Guide
// - Smart action routes will need to be added as you create new Smart Actions - Learn how to create a Smart Action here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/actions/create-and-manage-smart-actions
// Create a Cdt
router.post(‘/cdt’, permissionMiddlewareCreator.create(), (request, response, next) => {
// Learn what this route does here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/routes/default-routes#create-a-record
next();
});
// Update Status: Set Active
router.post(‘/actions/active’, permissionMiddlewareCreator.smartAction(), (request, response) => {
return new RecordsGetter(cdt).getIdsFromRequest(request)
.then((cdtIds) => {
return cdt
.update({cdtStatus:‘Active’}, {where: { id: cdtIds }})
.then(() => {
response.send({success: ‘CDT is now Active!’});
});
});
});
// Update a Cdt
router.put(‘/cdt/:recordId’, permissionMiddlewareCreator.update(), (request, response, next) => {
// Learn what this route does here: Default routes - Developer Guide
next();
});
// Delete a Cdt
router.delete(‘/cdt/:recordId’, permissionMiddlewareCreator.delete(), (request, response, next) => {
// Learn what this route does here: Default routes - Developer Guide
next();
});
// Get a list of Cdts
router.get(‘/cdt’, permissionMiddlewareCreator.list(), (request, response, next) => {
// Learn what this route does here: Default routes - Developer Guide
next();
});
// Get a number of Cdts
router.get(‘/cdt/count’, permissionMiddlewareCreator.list(), (request, response, next) => {
// Learn what this route does here: Default routes - Developer Guide
next();
});
// Get a Cdt
router.get(‘/cdt/:recordId’, permissionMiddlewareCreator.details(), (request, response, next) => {
// Learn what this route does here: Default routes - Developer Guide
next();
});
// Export a list of Cdts
router.get(‘/cdt.csv’, permissionMiddlewareCreator.export(), (request, response, next) => {
// Learn what this route does here: Default routes - Developer Guide
next();
});
// Delete a list of Cdts
router.delete(‘/cdt’, permissionMiddlewareCreator.delete(), (request, response, next) => {
// Learn what this route does here: Default routes - Developer Guide
next();
});
module.exports = router;
Pls help me review them, where is wrong?
Thanks & Regards!