feat(db/users): add settings column

This commit is contained in:
Aminejv 2021-12-09 12:27:18 +01:00
parent d57ee64c09
commit da00d27a4c
2 changed files with 17 additions and 6 deletions

View File

@ -1,7 +1,6 @@
import * as Environment from "~/node_common/environment";
import * as Data from "~/node_common/data";
import * as Utilities from "~/node_common/utilities";
import * as Serializers from "~/node_common/serializers";
import * as Validations from "~/common/validations";
import * as Social from "~/node_common/social";
import * as ViewerManager from "~/node_common/managers/viewer";
@ -38,6 +37,10 @@ export default async (req, res) => {
}
}
if (updates.settings) {
updates.settings = { ...user.settings, ...updates.settings };
}
if (updates.email && updates.email !== user.email) {
if (!Validations.email(updates.email)) {
return res.status(400).send({
@ -108,10 +111,7 @@ export default async (req, res) => {
}
try {
const configResponse = await b.buckets.setDefaultArchiveConfig(
b.bucketKey,
req.body.data.config
);
await b.buckets.setDefaultArchiveConfig(b.bucketKey, req.body.data.config);
} catch (e) {
Logging.error(e);
Social.sendTextileSlackMessage({

View File

@ -42,7 +42,18 @@ const addSlateCoverImage = db.schema.table("slates", function (table) {
table.jsonb("coverImage").nullable();
});
Promise.all([addSlateCoverImage]);
const addSettingsColumnToUsersTable = db.schema
.table("users", (table) => {
table.jsonb("settings").defaultTo("{}");
})
.then(() =>
db("users").update(
"settings",
db.raw("jsonb_build_object('filecoin', users.data -> 'settings' )")
)
);
Promise.all([addSettingsColumnToUsersTable]);
Logging.log(`FINISHED: adjust.js`);
Logging.log(` CTRL +C to return to terminal.`);