From 2337b9df7fc94cd7a37dd3e9446a7df5cfbf541c Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Fri, 1 Jun 2018 15:13:05 -0400 Subject: [PATCH] service -> serviceId --- .gitignore | 1 + app/models/Integration.js | 2 +- app/stores/IntegrationsStore.js | 2 +- server/api/hooks.js | 2 +- server/api/hooks.test.js | 2 +- server/api/team.test.js | 2 -- server/auth/slack.js | 8 ++++---- server/migrations/20180528233910-rename-serviceid.js | 10 ++++++++++ server/models/Authentication.js | 2 +- server/models/Integration.js | 2 +- server/presenters/integration.js | 2 +- server/services/slack/index.js | 2 +- 12 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 server/migrations/20180528233910-rename-serviceid.js diff --git a/.gitignore b/.gitignore index 2885433a..f00129f4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ dist node_modules/* .env +.log npm-debug.log stats.json .DS_Store diff --git a/app/models/Integration.js b/app/models/Integration.js index b1f67b34..fa4a8444 100644 --- a/app/models/Integration.js +++ b/app/models/Integration.js @@ -18,7 +18,7 @@ class Integration extends BaseModel { ui: UiStore; id: string; - serviceId: string; + service: string; collectionId: string; events: Events; settings: Settings; diff --git a/app/stores/IntegrationsStore.js b/app/stores/IntegrationsStore.js index 5bc4a391..39e065cf 100644 --- a/app/stores/IntegrationsStore.js +++ b/app/stores/IntegrationsStore.js @@ -23,7 +23,7 @@ class IntegrationsStore extends BaseStore { @computed get slackIntegrations(): Integration[] { - return _.filter(this.orderedData, { serviceId: 'slack' }); + return _.filter(this.orderedData, { service: 'slack' }); } @action diff --git a/server/api/hooks.js b/server/api/hooks.js index 8d9b9174..4c3eb354 100644 --- a/server/api/hooks.js +++ b/server/api/hooks.js @@ -20,7 +20,7 @@ router.post('hooks.unfurl', async ctx => { if (!user) return; const auth = await Authentication.find({ - where: { serviceId: 'slack', teamId: user.teamId }, + where: { service: 'slack', teamId: user.teamId }, }); if (!auth) return; diff --git a/server/api/hooks.test.js b/server/api/hooks.test.js index 0d7add05..3fc9b36f 100644 --- a/server/api/hooks.test.js +++ b/server/api/hooks.test.js @@ -18,7 +18,7 @@ describe('#hooks.unfurl', async () => { it('should return documents', async () => { const { user, document } = await seed(); await Authentication.create({ - serviceId: 'slack', + service: 'slack', userId: user.id, teamId: user.teamId, token: '', diff --git a/server/api/team.test.js b/server/api/team.test.js index 75b0963f..3a266cc3 100644 --- a/server/api/team.test.js +++ b/server/api/team.test.js @@ -52,8 +52,6 @@ describe('#team.update', async () => { const res = await server.post('/api/team.update', { body: { token: user.getJwtToken(), name: 'New name' }, }); - const body = await res.json(); - expect(res.status).toEqual(403); }); diff --git a/server/auth/slack.js b/server/auth/slack.js index eabd20af..115c0349 100644 --- a/server/auth/slack.js +++ b/server/auth/slack.js @@ -86,7 +86,7 @@ router.get('slack.commands', async ctx => { }); const authentication = await Authentication.create({ - serviceId: 'slack', + service: 'slack', userId: user.id, teamId: user.teamId, token: data.access_token, @@ -94,7 +94,7 @@ router.get('slack.commands', async ctx => { }); await Integration.create({ - serviceId: 'slack', + service: 'slack', type: 'command', userId: user.id, teamId: user.teamId, @@ -120,7 +120,7 @@ router.get('slack.post', async ctx => { }); const authentication = await Authentication.create({ - serviceId: 'slack', + service: 'slack', userId: user.id, teamId: user.teamId, token: data.access_token, @@ -128,7 +128,7 @@ router.get('slack.post', async ctx => { }); await Integration.create({ - serviceId: 'slack', + service: 'slack', type: 'post', userId: user.id, teamId: user.teamId, diff --git a/server/migrations/20180528233910-rename-serviceid.js b/server/migrations/20180528233910-rename-serviceid.js new file mode 100644 index 00000000..ce0a2aad --- /dev/null +++ b/server/migrations/20180528233910-rename-serviceid.js @@ -0,0 +1,10 @@ +module.exports = { + up: async (queryInterface, Sequelize) => { + await queryInterface.renameColumn('authentications', 'serviceId', 'service'); + await queryInterface.renameColumn('integrations', 'serviceId', 'service'); + }, + down: async (queryInterface, Sequelize) => { + await queryInterface.renameColumn('authentications', 'service', 'serviceId'); + await queryInterface.renameColumn('integrations', 'service', 'serviceId'); + } +} \ No newline at end of file diff --git a/server/models/Authentication.js b/server/models/Authentication.js index 85a07abe..e4a479dd 100644 --- a/server/models/Authentication.js +++ b/server/models/Authentication.js @@ -7,7 +7,7 @@ const Authentication = sequelize.define('authentication', { defaultValue: DataTypes.UUIDV4, primaryKey: true, }, - serviceId: DataTypes.STRING, + service: DataTypes.STRING, scopes: DataTypes.ARRAY(DataTypes.STRING), token: encryptedFields.vault('token'), }); diff --git a/server/models/Integration.js b/server/models/Integration.js index 99b9aa32..9251ba7c 100644 --- a/server/models/Integration.js +++ b/server/models/Integration.js @@ -8,7 +8,7 @@ const Integration = sequelize.define('integration', { primaryKey: true, }, type: DataTypes.STRING, - serviceId: DataTypes.STRING, + service: DataTypes.STRING, settings: DataTypes.JSONB, events: DataTypes.ARRAY(DataTypes.STRING), }); diff --git a/server/presenters/integration.js b/server/presenters/integration.js index eb0099f3..619d7cd4 100644 --- a/server/presenters/integration.js +++ b/server/presenters/integration.js @@ -7,9 +7,9 @@ function present(ctx: Object, integration: Integration) { type: integration.type, userId: integration.userId, teamId: integration.teamId, - serviceId: integration.serviceId, collectionId: integration.collectionId, authenticationId: integration.authenticationId, + service: integration.service, events: integration.events, settings: integration.settings, createdAt: integration.createdAt, diff --git a/server/services/slack/index.js b/server/services/slack/index.js index d40f10b0..b2e5fd21 100644 --- a/server/services/slack/index.js +++ b/server/services/slack/index.js @@ -14,8 +14,8 @@ const Slack = { const integration = await Integration.findOne({ where: { teamId: document.teamId, - serviceId: 'slack', collectionId: document.atlasId, + service: 'slack', type: 'post', }, });