| 493 | } |
| 494 | |
| 495 | deleteApiKey(keyId, teamId) { |
| 496 | const whereCondition = teamId |
| 497 | ? { id: keyId, team_id: teamId } |
| 498 | : { id: keyId }; |
| 499 | |
| 500 | return db.Apikey.findOne({ where: whereCondition }) |
| 501 | .then((apiKey) => { |
| 502 | if (!apiKey) { |
| 503 | return Promise.reject(new Error(404)); |
| 504 | } |
| 505 | return db.TokenBlacklist.create({ token: apiKey.token }); |
| 506 | }) |
| 507 | .then(() => { |
| 508 | return db.Apikey.destroy({ where: whereCondition }); |
| 509 | }) |
| 510 | .then((result) => { |
| 511 | if (result === 0) { |
| 512 | return Promise.reject(new Error(404)); |
| 513 | } |
| 514 | return result; |
| 515 | }) |
| 516 | .catch((err) => { |
| 517 | return Promise.reject(err); |
| 518 | }); |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | module.exports = TeamController; |