Skip to content

Commit

Permalink
agrega claustros schema
Browse files Browse the repository at this point in the history
  • Loading branch information
xtian7489 committed Apr 25, 2024
1 parent 98c9f5b commit 8c8e543
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 14 deletions.
27 changes: 27 additions & 0 deletions lib/models/claustro.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const mongoose = require('mongoose')
const Schema = mongoose.Schema

const ClaustroSchema = new Schema({
nombre: { type: String, required: true, minlength: 1, maxlength: 200 }
}, { id: false })
// esto último hace que no esté el campo _id e id duplicado

ClaustroSchema.statics.findByName = function (name, cb) {
return this.findOne({ name: name }).exec(cb)
}

/**
* Make Schema `.toObject()` and
* `.toJSON()` parse getters for
* proper JSON API response
*/

ClaustroSchema.set('toObject', { getters: true })
ClaustroSchema.set('toJSON', { getters: true })
/**
* Expose Model
*/

module.exports = function initialize(conn) {
return conn.model('Claustro', ClaustroSchema)
}
1 change: 1 addition & 0 deletions lib/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module.exports = exports = function models () {
exports.User = require('./user')(usersDb)
exports.Text = require('./text')(connection)
exports.Facultad = require('./facultad')(connection)
exports.Claustro = require('./claustro')(connection)
exports.Padron = require('./padron')(connection)
exports.aboutUs = require('./aboutUs')(connection)

Expand Down
47 changes: 33 additions & 14 deletions migrations/2000000000005-cargar-facultades.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
const dbReady = require('lib/models').ready
const models = require('lib/models')

const nombreMigrationParaLog = 'cargar facultades'
const nombreMigrationParaLog = 'cargar facultades y claustros'
const Facultad = models.Facultad
const Claustro = models.Claustro

const facultades = [

{ nombre: 'CNAI'},
{ nombre: 'ESM'},
{ nombre: 'F.PSICO'},
{ nombre: 'FAUD'},
{ nombre: 'FCA'},
{ nombre: 'FCEyN'},
{ nombre: 'FCEyS'},
{ nombre: 'FCSYTS'},
{ nombre: 'FD'},
{ nombre: 'FH'},
{ nombre: 'FI'},
{ nombre: 'Rec'},
{ nombre: 'Arquitectura, Urbanismo y Diseño', abreviacion: 'FAUD' },
{ nombre: 'Facultad de Ciencias Agrarias', abreviacion: 'FCA' },
{ nombre: 'Facultad de Ciencias de la Salud y Trabajo Social', abreviacion: 'FCSYTS' },
{ nombre: 'Facultad de Ciencias Económicas y Sociales', abreviacion: 'FCEyS' },
{ nombre: 'Facultad de Ciencias Exactas y Naturales', abreviacion: 'FCEyN' },
{ nombre: 'Facultad de Derecho', abreviacion: 'FD' },
{ nombre: 'Facultad de Humanidades', abreviacion: 'FH' },
{ nombre: 'Facultad de Ingeniería', abreviacion: 'FI' },
{ nombre: 'Facultad de Psicologia', abreviacion: 'F.PSICO' },
{ nombre: 'Escuela Superior de Medicina', abreviacion: 'ESM' },
{ nombre: 'Colegio Nacional Arturo Illia', abreviacion: 'CNAI' },
{ nombre: 'Rectorado', abreviacion: 'Rec' },
]
const claustros = [
{ nombre: 'Estudiantes' },
{ nombre: 'Docentes' },
{ nombre: 'Nodocentes' },
{ nombre: 'Graduados/as' },
]

/**
Expand All @@ -40,9 +46,22 @@ exports.up = function up (done) {
})
})
})
.then(() => {
return new Promise((resolve, reject) => {
Claustro.collection.count({}, (err, count) => {
if (err) reject(new Error(err))
if (count) {
console.log('Ya hay claustros cargados (%s), salteando migración', count)
reject(new SaltearPromises())
}
resolve()
})
})
})

// Agregamos data
.then(() => Facultad.collection.insertMany(facultades))
.then(() => Claustro.collection.insertMany(claustros))

// Todo OK
.then(() => {
Expand Down

0 comments on commit 8c8e543

Please sign in to comment.