Skip to content

Commit

Permalink
#352 Templating 1
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqksoliman committed Mar 16, 2023
1 parent 2e3450f commit 3fc6242
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 25 deletions.
25 changes: 24 additions & 1 deletion API/Backend/Draw/models/userfiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ const attributes = {
defaultValue: "0",
unique: false,
},
template: {
type: Sequelize.JSON,
allowNull: true,
defaultValue: null,
},
};

const options = {
Expand Down Expand Up @@ -128,5 +133,23 @@ const makeMasterFiles = (intents) => {
}
};

// Adds to the table, never removes
const up = async () => {
// template column
await sequelize
.query(
`ALTER TABLE user_files ADD COLUMN IF NOT EXISTS template json NULL;`
)
.then(() => {
logger("info", `Added template col`, "user_files");
return null;
})
.catch((err) => {
logger("info", `template. Nothing to do...`, "user_files");

return null;
});
};

// export User model for use in other files.
module.exports = { Userfiles, UserfilesTEST, makeMasterFiles };
module.exports = { Userfiles, UserfilesTEST, makeMasterFiles, up };
1 change: 1 addition & 0 deletions API/Backend/Draw/routes/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ router.post("/make", function (req, res, next) {
intent: req.body.intent,
public: "1",
hidden: "0",
template: req.body.template ? JSON.parse(req.body.template) : null,
};

// Insert new userfile into the user_files table
Expand Down
4 changes: 4 additions & 0 deletions API/Backend/Draw/setup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const routeFiles = require("./routes/files");
const routerFiles = routeFiles.router;
const routerDraw = require("./routes/draw").router;
const ufiles = require("./models/userfiles");

let setup = {
//Once the app initializes
Expand All @@ -27,6 +28,9 @@ let setup = {
onceStarted: (s) => {},
//Once all tables sync
onceSynced: (s) => {
if (typeof ufiles.up === "function") {
ufiles.up();
}
routeFiles.makeMasterFiles([
"roi",
"campaign",
Expand Down
52 changes: 28 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3fc6242

Please sign in to comment.