Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BC-6111 - default system and federal state #4665

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion backup/setup/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,18 @@
},
{
"_id": {
"$oid": "658434b45fcf755f84d80cb6"
"$oid": "6585950b4903600babed0d79"
},
"state": "up",
"name": "school-default-props",
"createdAt": {
"$date": "2023-12-22T13:54:19.864Z"
},
"__v": 0
},
{
"_id": {
"$oid": "6585979f8eef141a0615da6f"
},
"state": "up",
"name": "add-protected-field-to-custom-paramters",
Expand Down
76 changes: 76 additions & 0 deletions migrations/1703253259864-school-default-props.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const mongoose = require('mongoose');
// eslint-disable-next-line no-unused-vars
const { alert, error } = require('../src/logger');

const { connect, close } = require('../src/utils/database');

const { Schema } = mongoose;

const School = mongoose.model(
'schools202312111053',
new mongoose.Schema(
{
systems: [{ type: Schema.Types.ObjectId, ref: 'system' }],
federalState: { type: Schema.Types.ObjectId, ref: 'federalstate' },
},
{
timestamps: true,
}
),
'schools'
);

const FederalState = mongoose.model(
'federalState202312111053',
new mongoose.Schema(
{
name: { type: String, required: true },
},
{
timestamps: true,
}
),
'federalstates'
);

module.exports = {
up: async function up() {
await connect();

await School.updateMany(
{
systems: { $exists: false },
},
{
systems: [],
}
)
.lean()
.exec();

const tenant = process.env.SC_THEME;
let federalStateName = 'Brandenburg';
if (tenant !== 'n21') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeeh, that would be Brandenburg, set above....This is not cleared with PO, but we have only test schools

federalStateName = 'Niedersachsen';
} else if (tenant === 'brb') {
federalStateName = 'Brandenburg';
} else if (tenant === 'thr') {
federalStateName = 'Thüringen';
}

const federalState = await FederalState.findOne({ name: federalStateName }).lean().exec();

await School.updateMany(
{
federalState: { $exists: false },
},
{
federalState: federalState._id,
}
)
.lean()
.exec();

await close();
},
};
Loading