-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Widget multi events support (#161)
- Loading branch information
Showing
16 changed files
with
396 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const { DataTypes } = require("sequelize"); | ||
const sequelize = require("../index"); | ||
|
||
const StoreMigration = sequelize.define("StoreMigration", { | ||
name: { | ||
type: DataTypes.STRING, | ||
allowNull: false, | ||
unique: true, | ||
}, | ||
}); | ||
|
||
module.exports = StoreMigration; |
31 changes: 31 additions & 0 deletions
31
app/server/db/migrations/20210220100805-store-migration.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"use strict"; | ||
|
||
const { Sequelize } = require("sequelize"); | ||
|
||
const storeMigrations = { | ||
id: { | ||
type: Sequelize.INTEGER, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
}, | ||
name: { | ||
type: Sequelize.STRING, | ||
allowNull: false, | ||
unique: true, | ||
}, | ||
createdAt: { | ||
type: Sequelize.DATE, | ||
defaultValue: Sequelize.NOW, | ||
}, | ||
updatedAt: { | ||
type: Sequelize.DATE, | ||
defaultValue: Sequelize.NOW, | ||
}, | ||
}; | ||
|
||
module.exports = { | ||
up: async ({ context }) => { | ||
await context.createTable("StoreMigrations", storeMigrations); | ||
}, | ||
down: async () => {}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const StoreMigration = require("../server/db/Models/StoreMigration"); | ||
const loggers = require("../server/libs/loggers"); | ||
const path = require("path"); | ||
const fs = require("fs"); | ||
|
||
const migrationsPath = path.join(__dirname, "migrations"); | ||
const logger = loggers.get("server"); | ||
|
||
async function up() { | ||
const files = fs.readdirSync(migrationsPath).sort((a, b) => a - b); | ||
const migrations = await StoreMigration.findAll({ | ||
attributes: ["name"], | ||
raw: true, | ||
}); | ||
|
||
for (let i = 0, l = files.length; i < l; i++) { | ||
const file = files[i]; | ||
if (!migrations.find((m) => m.name === file)) { | ||
logger.info(`[store] migration from ${file}`); | ||
const { up } = require(path.join(migrationsPath, file)); | ||
await up(); | ||
StoreMigration.create({ name: file }); | ||
} | ||
} | ||
} | ||
|
||
async function down() { | ||
logger.warn("[store] up method not implemented !!!"); | ||
} | ||
|
||
module.exports = { | ||
up, | ||
down, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const { panels: store } = require("../index"); | ||
|
||
function clean(widget) { | ||
delete widget.eventName; | ||
delete widget.commandName; | ||
delete widget.rewardId; | ||
delete widget.shortcutName; | ||
} | ||
|
||
module.exports = { | ||
up: async () => { | ||
const panels = store.get("panels"); | ||
|
||
panels.forEach((panel) => { | ||
panel.widgets.forEach((widget) => { | ||
widget.events = widget.events || []; | ||
|
||
const event = {}; | ||
|
||
if (!widget.eventName || widget.eventName === "none") { | ||
clean(widget); | ||
return; | ||
} | ||
|
||
event.eventName = widget.eventName; | ||
|
||
if (event.eventName === "onCommand") { | ||
event.commandName = widget.commandName; | ||
} else if (event.eventName === "onRedemption") { | ||
event.rewardId = widget.rewardId; | ||
} else if (event.eventName === "onShortcut") { | ||
event.shortcutName = widget.shortcutName; | ||
} | ||
|
||
if (Object.keys(event).length) { | ||
widget.events.push(event); | ||
} | ||
|
||
clean(widget); | ||
}); | ||
}); | ||
|
||
store.set("panels", panels); | ||
}, | ||
down: async () => {}, | ||
}; |
Oops, something went wrong.