Skip to content

Commit

Permalink
fix migrazione
Browse files Browse the repository at this point in the history
  • Loading branch information
paolini committed Oct 22, 2023
1 parent dc02278 commit fd503ee
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
15 changes: 9 additions & 6 deletions server/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ async function findPerson2(people, fullName, affiliazione) {
let p = null
if (names.length === 2) {
return await findPerson(people, names[0], names[1], affiliazione)
} else if (names.length ===3 && ['de','di','da','dal','del'].includes(names[1].lower())) {
return await findPerson(people, names[0], `${names[1]} ${names[2]}`)
} else {
// find people where firstName + lastName equals fullName
p = await people.aggregate([
Expand Down Expand Up @@ -377,7 +379,7 @@ const migrations = {
return true
},

D20231013_copy_events_8: async function(db) {
D20231013_copy_events_9: async function(db) {
const people = db.collection('people')
const conferences = db.collection('eventconferences')
const seminars = db.collection('eventseminars')
Expand Down Expand Up @@ -587,7 +589,7 @@ const migrations = {
const duration = (event.unipievents_enddate - event.unipievents_startdate) / 60
const notes = event.content.rendered
const abstract = event.content.rendered
const old_url = event.link
const oldUrl = event.link

if (taxonomy.includes(90)) {
console.log("> Conference", event.link)
Expand All @@ -598,7 +600,7 @@ const migrations = {
endDate: toUTCDate(event.unipievents_enddate),
SSD: event.unipievents_taxonomy.map(categoryToSSD).filter(x => x),
url: "",
old_url,
oldUrl,
conferenceRoom,
grants: [],
notes,
Expand All @@ -620,13 +622,13 @@ const migrations = {
speaker: person,
duration,
abstract,
old_url,
oldUrl,
grants: [],
}
await seminars.insertOne(object)
} else {
// console.log("> Seminar", event.link)
// console.log(taxonomy, event.link)
console.log(taxonomy, event.link)
// console.log("title", title)
let speaker = null
try {
Expand All @@ -649,6 +651,7 @@ const migrations = {
duration,
category: created_categories[taxonomy[0]] || created_categories[taxonomy[1]],
grants: [],
oldUrl,
abstract: notes,
}
//console.log(object)
Expand All @@ -660,7 +663,7 @@ const migrations = {

}
res = await axios.get(`https://www.dm.unipi.it/wp-json/wp/v2/unipievents?per_page=${batch_size}&offset=${offset}`)
console.log(`BATCh ${offset}`)
console.log(`>>>> BATCH ${offset}`)
offset += batch_size
}

Expand Down
3 changes: 2 additions & 1 deletion server/models/EventConference.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const eventConferenceSchema = new Schema({
startDate,
endDate,
SSD: multipleSSDs,
url: { type: String, label: 'Sito web' },
url: { type: String, label: 'Sito web', widget: 'url' },
oldUrl: { type: String, label: 'URL vecchio', widget: 'url' },
conferenceRoom: { type: ObjectId, label: 'Aula', ref: 'ConferenceRoom', required: true },
grants: [{type: ObjectId, label: 'grants', ref: 'Grant'}],
notes,
Expand Down
13 changes: 11 additions & 2 deletions server/models/EventSeminar.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ const eventSeminarSchema = new Schema({
category: { type: ObjectId, label: 'Ciclo di Seminari', ref: 'SeminarCategory', required: true },
grants: [{type: ObjectId, label: 'grants', ref: 'Grant'}],
abstract: { type: String, label: 'Abstract', widget: 'text' },

oldUrl: { type: String, label: 'URL vecchio', widget: 'url' },

createdBy,
updatedBy,
}, {
timestamps: true
})

const EventSeminar = model('EventSeminar', eventSeminarSchema)
module.exports = EventSeminar

Grant.relatedModels.push({
model: EventSeminar,
Expand All @@ -34,4 +36,11 @@ Grant.relatedModels.push({
multiple: true,
})

module.exports = EventSeminar
const Person = require('./Person')
Person.relatedModels.push({
model: EventSeminar,
modelName: 'EventSeminar',
url: 'event-seminar',
field: 'speaker',
multiple: false,
})

0 comments on commit fd503ee

Please sign in to comment.