alphascript-server
Version:
CRUD operations for mongo and other functionalities to get started quickly in any CMS project
275 lines (242 loc) • 9.7 kB
JavaScript
var randToken = require('rand-token').uid;
var validator = require('validator');
var fs = require('fs');
var api = require('../../../');
var path = require('path');
module.exports = function (mongoose) {
return {
user: {
//all users
username: { type: String, unique: [true, "Username duplicado"], required: [true, "Username é obrigatório"] },
email: {
type: String, required: [true, "Email é obrigatório"],
validate: {
validator: function (value) {
return validator.isEmail(value);
},
message: "{VALUE} não é um email válido"
}
},
role: { type: mongoose.Schema.Types.ObjectId, ref: 'role', required: [true, "Deve selecionar um perfil de utilizador"] },
name: { type: String },
//owners
company: { type: String },
nif: { type: String },
landline: { type: String },
addressDetails: { type: String },
address: { type: String },
postalCode: { type: String },
city: { type: String },
locality: { type: String },
county: { type: String },
country: { type: mongoose.Schema.Types.ObjectId },
//system
password: { type: String },
activation: {
type: String,
default: function () {
return randToken(64);
}
},
isFirstLogin: { type: Boolean, default: true },
changepw: { type: Boolean, default: true },
owner: { type: mongoose.Schema.Types.ObjectId, ref: 'user' }
},
role: {
name: { type: String, required: [true, "Nome do perfil é obrigatório"], unique: [true, "Nome do perfil duplicado"] },
admin: { type: Boolean, default: false },
approvalLevel: { type: Number, default: 0 }
},
license: {
customer: { type: mongoose.Schema.Types.ObjectId, ref: 'user', required: [true, "Deve selecionar um utilizador"] },
modules: [{ type: mongoose.Schema.Types.ObjectId, ref: 'module', required: [true, "Deve selecionar um módulo"] }],
dateStart: { type: Date, required: [true, "Data de início obrigatória"] },
dateEnd: { type: Date, required: [true, "Data de termo obrigatória"] },
invoice: { type: String },
owner: { type: mongoose.Schema.Types.ObjectId, ref: 'user', required: [true, "É obrigatório, para efeitos de histórico, gravar quem criou/alterou o registo"] }
},
module: {
name: { type: String, required: [true, "Nome do módulo é obrigatório"], unique: [true, "Módulo duplicado"] },
description: { type: String },
is_core: { type: Boolean, default: false },
price: [{
index: { type: Number, required: [true, "É obrigatório designar o indice de todos os preços"] },
value: { type: Number, required: [true, "É obrigatório indicar o valor de todos os preços"] }
}]
},
alert: {
name: { type: String, required: [true, "Nome do alerta é obrigatório"], unique: [true, "Alerta duplicado"] },
template: {
type: String, required: [true, "Template do alerta é obrigatório"],
validate: {
validator: function (value) {
var emailPath = path.join(api.options.emailRoot, value);
return fs.existsSync(emailPath);
},
message: "Não existe nenhum template '{VALUE}'"
}
},
active: { type: Boolean, default: true },
fromSelf: { type: Boolean, default: false },
fromCoordinator: { type: Boolean, default: false },
from: [{
email: { type: String, required: [true, "Email 'de' obrigatório"] }
}],
toSelf: { type: Boolean, default: false },
toCoordinator: { type: Boolean, default: false },
to: [{
email: { type: String, required: [true, "Email 'para' obrigatório"] }
}],
ccSelf: { type: Boolean, default: false },
ccCoordinator: { type: Boolean, default: false },
cc: [{
email: { type: String, required: [true, "Email 'cc' obrigatório"] }
}],
subject: { type: String, required: [true, "Assunto é obrigatório"] },
attachments: [{
name: { type: String, required: [true, "Nome do anexo é obrigatório"] },
document: { type: mongoose.Schema.Types.ObjectId, ref: 'document', required: [true, "Ficheiro de anexo é obrigatório"] },
cid: { type: String }
}]
},
task: {
type: {
type: String, required: [true, "Tipo de tarefa obrigatório"],
validate: {
validator: function (value) {
return !!api.taskMap[value];
},
message: "Não existe nenhuma tarefa '{VALUE}'"
}
},
isActive: { type: Boolean, default: false },
runs: [{ type: mongoose.Schema.Types.ObjectId, ref: 'run' }],
name: { type: String, required: [true, "Nome do agendamento obrigatório"], unique: [true, "Agendamento duplicado"] },
criteria: {
month: { type: String, required: [true, "Critério 'mês' obrigatório"] },
monthday: { type: String, required: [true, "Critério 'dia do mês' obrigatório"] },
weekday: { type: String, required: [true, "Critério 'dia da semana' obrigatório"] },
hour: { type: String, required: [true, "Critério 'hora' obrigatório"] },
minute: { type: String, required: [true, "Critério 'minuto' obrigatório"] }
}
},
holiday: {
name: { type: String, required: [true, "Nome do feriado obrigatório"], unique: [true, "Feriado duplicado"] },
isLocal: { type: Boolean, default: false },
country: { type: mongoose.Schema.Types.ObjectId, ref: 'country' },
format: { type: String, required: [true, "Formato obrigatório"] },
date: {
type: String,
required: [function () {
return !this.formula;
}, "Deve indicar uma data fixa ou a formula de uma data dinâmica"]
},
formula: {
type: String,
required: [function () {
return !this.date;
}, "Deve indicar uma data fixa ou a formula de uma data dinâmica"]
}
},
address: {
street: { type: String },
city: { type: String },
district: { type: String },
county: { type: String },
locality: { type: String },
postalCode: { type: String },
postalExtension: { type: String }
},
country: {
name: {
common: { type: String },
official: { type: String },
native: { type: mongoose.Schema.Types.Mixed }
},
tld: [{ type: String }],
cca2: { type: String },
ccn3: { type: String },
cca3: { type: String },
cioc: { type: String },
currency: [{ type: String }],
callingCode: [{ type: String }],
capital: { type: String },
altSpellings: [{ type: String }],
region: { type: String },
subregion: { type: String },
languages: { type: mongoose.Schema.Types.Mixed },
translations: { type: mongoose.Schema.Types.Mixed },
latlng: [
{ type: Number },
{ type: Number }
],
demonym: { type: String },
landlocked: { type: Boolean },
borders: [{ type: String }],
area: { type: Number }
},
activity: {
who: { type: String },
what: { type: String },
action: { type: String, required: [true, "Descrição da ação é obrigatória"] },
where: { type: String }
},
error: {
description: { type: String, required: [true, "Descrição do erro é obrigatória"] },
data: { type: mongoose.Schema.Types.Mixed }
},
document: {
filename: { type: String },
size: { type: Number },
hash: { type: String },
domain: { type: String },
lastModifiedDate: { type: Date },
type: { type: String },
filepath: { type: String, required: [true, "Caminho do ficheiro é obrigatório"] }
},
maintenance: {
reason: { type: String, required: [true, "Motivo da manutenção é obrigatório"] }
},
message: {
template: { type: String, required: [true, "Template usado para a despoletação do email é obrigatório"] },
subject: { type: String, required: [true, "Assunto é obrigatório"] },
from: { type: String, required: [true, "Endereço 'de' obrigatório"] },
to: [{ type: String, required: [true, "Endereço 'para' obrigatório"] }],
cc: [{ type: String, required: [true, "Endereço 'cc' obrigatório"] }],
text: { type: String },
html: { type: String },
attachments: [{
filename: { type: String },
path: { type: String },
cid: { type: String }
}]
},
run: {
isRunning: { type: Boolean, default: true },
success: { type: Boolean },
error: { type: String },
startTimestamp: { type: Date, default: Date.now },
endTimestamp: { type: Date }
},
newsletter: {
name: { type: String },
email: { type: String, required: [true, "Email é obrigatório"] }
},
report: {
key: { type: String, required: [true, "Chave da listagem parametrizada é obrigatória"] },
name: { type: String, required: [true, "Nome da listagem parametrizada é obrigatório"] },
user: { type: mongoose.Schema.Types.ObjectId, ref: 'user' }
},
slider: {
idSlide: { type: Number },
title: { type: String },
image: { type: mongoose.Schema.Types.ObjectId, ref: 'document' },
text: { type: String },
btntext: { type: String },
btnlink: { type: String },
targetlink: { type: String },
carousel_caption_style: { type: String },
active: { type: Boolean }
}
};
};