94 lines
1.8 KiB
JavaScript
94 lines
1.8 KiB
JavaScript
const config = require('../../config');
|
|
const providers = config.providers;
|
|
const crypto = require('crypto');
|
|
const bcrypt = require('bcrypt');
|
|
const moment = require('moment');
|
|
|
|
module.exports = function (sequelize, DataTypes) {
|
|
const maps = sequelize.define(
|
|
'maps',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
title: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
subtitle: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
show_basemap: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
},
|
|
|
|
show_admin_boundaries: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
},
|
|
|
|
latitude: {
|
|
type: DataTypes.DECIMAL,
|
|
},
|
|
|
|
longitude: {
|
|
type: DataTypes.DECIMAL,
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
maps.associate = (db) => {
|
|
db.maps.belongsToMany(db.map_layers, {
|
|
as: 'layers',
|
|
foreignKey: {
|
|
name: 'maps_layersId',
|
|
},
|
|
constraints: false,
|
|
through: 'mapsLayersMap_layers',
|
|
});
|
|
|
|
db.maps.belongsToMany(db.map_layers, {
|
|
as: 'layers_filter',
|
|
foreignKey: {
|
|
name: 'maps_layersId',
|
|
},
|
|
constraints: false,
|
|
through: 'mapsLayersMap_layers',
|
|
});
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
//end loop
|
|
|
|
db.maps.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.maps.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
return maps;
|
|
};
|