|
|
@@ -65,21 +65,21 @@ export class SlackCtrl {
|
|
|
* @param body
|
|
|
* @returns
|
|
|
*/
|
|
|
- private async sendCommand(growiCommand: GrowiCommand, relationMocks: RelationMock[], body: any) {
|
|
|
- if (relationMocks.length === 0) {
|
|
|
+ private async sendCommand(growiCommand: GrowiCommand, relations: RelationMock[], body: any) {
|
|
|
+ if (relations.length === 0) {
|
|
|
throw new Error('relations must be set');
|
|
|
}
|
|
|
- const botToken = relationMocks[0].installation?.data.bot?.token; // relations[0] should be exist
|
|
|
+ const botToken = relations[0].installation?.data.bot?.token; // relations[0] should be exist
|
|
|
|
|
|
- const promises = relationMocks.map((relationMock: RelationMock) => {
|
|
|
+ const promises = relations.map((relation: RelationMock) => {
|
|
|
// generate API URL
|
|
|
- const url = new URL('/_api/v3/slack-integration/proxied/commands', relationMock.growiUri);
|
|
|
+ const url = new URL('/_api/v3/slack-integration/proxied/commands', relation.growiUri);
|
|
|
return axios.post(url.toString(), {
|
|
|
...body,
|
|
|
growiCommand,
|
|
|
}, {
|
|
|
headers: {
|
|
|
- 'x-growi-ptog-tokens': relationMock.tokenPtoG,
|
|
|
+ 'x-growi-ptog-tokens': relation.tokenPtoG,
|
|
|
},
|
|
|
});
|
|
|
});
|
|
|
@@ -136,12 +136,12 @@ export class SlackCtrl {
|
|
|
const installationId = authorizeResult.enterpriseId || authorizeResult.teamId;
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
|
const installation = await this.installationRepository.findByTeamIdOrEnterpriseId(installationId!);
|
|
|
- const relationMocks = await this.relationMockRepository.createQueryBuilder('relation_mock')
|
|
|
- .where('relation_mock.installationId = :id', { id: installation?.id })
|
|
|
- .leftJoinAndSelect('relation_mock.installation', 'installation')
|
|
|
+ const relations = await this.relationMockRepository.createQueryBuilder('relation')
|
|
|
+ .where('relation.installationId = :id', { id: installation?.id })
|
|
|
+ .leftJoinAndSelect('relation.installation', 'installation')
|
|
|
.getMany();
|
|
|
|
|
|
- if (relationMocks.length === 0) {
|
|
|
+ if (relations.length === 0) {
|
|
|
return res.json({
|
|
|
blocks: [
|
|
|
markdownSectionBlock('*No relation found.*'),
|
|
|
@@ -155,7 +155,7 @@ export class SlackCtrl {
|
|
|
return res.json({
|
|
|
blocks: [
|
|
|
markdownSectionBlock('*Found Relations to GROWI.*'),
|
|
|
- ...relationMocks.map(relationMock => markdownSectionBlock(`GROWI url: ${relationMock.growiUri}`)),
|
|
|
+ ...relations.map(relation => markdownSectionBlock(`GROWI url: ${relation.growiUri}`)),
|
|
|
],
|
|
|
});
|
|
|
}
|
|
|
@@ -166,40 +166,40 @@ export class SlackCtrl {
|
|
|
|
|
|
const baseDate = new Date();
|
|
|
|
|
|
- const relationMocksForSingleUse:RelationMock[] = [];
|
|
|
- await Promise.all(relationMocks.map(async(relationMock) => {
|
|
|
- const isSupported = await this.relationsService.isSupportedGrowiCommandForSingleUse(relationMock, growiCommand.growiCommandType, baseDate);
|
|
|
+ const relationsForSingleUse:RelationMock[] = [];
|
|
|
+ await Promise.all(relations.map(async(relation) => {
|
|
|
+ const isSupported = await this.relationsService.isSupportedGrowiCommandForSingleUse(relation, growiCommand.growiCommandType, baseDate);
|
|
|
if (isSupported) {
|
|
|
- relationMocksForSingleUse.push(relationMock);
|
|
|
+ relationsForSingleUse.push(relation);
|
|
|
}
|
|
|
}));
|
|
|
|
|
|
let isCommandPermitted = false;
|
|
|
|
|
|
- if (relationMocksForSingleUse.length > 0) {
|
|
|
+ if (relationsForSingleUse.length > 0) {
|
|
|
isCommandPermitted = true;
|
|
|
- body.growiUrisForSingleUse = relationMocksForSingleUse.map(v => v.growiUri);
|
|
|
+ body.growiUrisForSingleUse = relationsForSingleUse.map(v => v.growiUri);
|
|
|
return this.selectGrowiService.process(growiCommand, authorizeResult, body);
|
|
|
}
|
|
|
|
|
|
- const relationMocksForBroadcastUse:RelationMock[] = [];
|
|
|
- await Promise.all(relationMocks.map(async(relationMock) => {
|
|
|
- const isSupported = await this.relationsService.isSupportedGrowiCommandForBroadcastUse(relationMock, growiCommand.growiCommandType, baseDate);
|
|
|
+ const relationsForBroadcastUse:RelationMock[] = [];
|
|
|
+ await Promise.all(relations.map(async(relation) => {
|
|
|
+ const isSupported = await this.relationsService.isSupportedGrowiCommandForBroadcastUse(relation, growiCommand.growiCommandType, baseDate);
|
|
|
if (isSupported) {
|
|
|
- relationMocksForBroadcastUse.push(relationMock);
|
|
|
+ relationsForBroadcastUse.push(relation);
|
|
|
}
|
|
|
}));
|
|
|
|
|
|
/*
|
|
|
* forward to GROWI server
|
|
|
*/
|
|
|
- if (relationMocksForBroadcastUse.length > 0) {
|
|
|
+ if (relationsForBroadcastUse.length > 0) {
|
|
|
isCommandPermitted = true;
|
|
|
- this.sendCommand(growiCommand, relationMocksForBroadcastUse, body);
|
|
|
+ this.sendCommand(growiCommand, relationsForBroadcastUse, body);
|
|
|
}
|
|
|
|
|
|
if (!isCommandPermitted) {
|
|
|
- const botToken = relationMocks[0].installation?.data.bot?.token;
|
|
|
+ const botToken = relations[0].installation?.data.bot?.token;
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
|
const client = generateWebClient(botToken!);
|
|
|
@@ -265,7 +265,7 @@ export class SlackCtrl {
|
|
|
// forward to GROWI server
|
|
|
if (callBackId === 'select_growi') {
|
|
|
const selectedGrowiInformation = await this.selectGrowiService.handleSelectInteraction(installation, payload);
|
|
|
- return this.sendCommand(selectedGrowiInformation.growiCommand, [selectedGrowiInformation.relationMock], selectedGrowiInformation.sendCommandBody);
|
|
|
+ return this.sendCommand(selectedGrowiInformation.growiCommand, [selectedGrowiInformation.relation], selectedGrowiInformation.sendCommandBody);
|
|
|
}
|
|
|
|
|
|
/*
|