Skip to content

Commit

Permalink
feat: enable users to remove Notion connection (#1568)
Browse files Browse the repository at this point in the history
Currently only possible by deleting account.
  • Loading branch information
aalemayhu authored Aug 5, 2024
1 parent 4152c92 commit 22d16d3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/controllers/NotionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@ class NotionController {
const results = await api.queryDatabase(id);
res.json(results);
}

async disconnect(_req: Request, res: Response) {
try {
const deletion = await this.service.disconnect(res.locals.owner);
res.status(200).send({ didDelete: deletion });
} catch (err) {
sendError(err);
console.debug('Failed to disconnect');
res.status(500).send({ didDelete: false });
}
}
}

export default NotionController;
8 changes: 8 additions & 0 deletions src/data_layer/NotionRespository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface INotionRepository {
): Promise<boolean>;
getNotionToken(owner: string): Promise<string>;
deleteBlocksByOwner(owner: number): Promise<number>;
deleteNotionData(owner: number): Promise<boolean>;
}

class NotionRepository implements INotionRepository {
Expand Down Expand Up @@ -81,6 +82,13 @@ class NotionRepository implements INotionRepository {
deleteBlocksByOwner(owner: number): Promise<number> {
return this.database(this.notionBlocksTable).del().where({ owner });
}

/**
* Delete the users notion token when they disconnect
*/
deleteNotionData(owner: number | string): Promise<boolean> {
return this.database(this.notionTokensTable).where({ owner: owner }).del();
}
}

export default NotionRepository;
4 changes: 4 additions & 0 deletions src/routes/NotionRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ const NotionRouter = () => {
(req, res) => controller.queryDatabase(req, res)
);

router.post('/api/notion/disconnect', RequireAuthentication, (req, res) =>
controller.disconnect(req, res)
);

return router;
};

Expand Down
4 changes: 4 additions & 0 deletions src/services/NotionService/NotionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,8 @@ export class NotionService {
getClientId() {
return this.clientId;
}

disconnect(owner: number) {
return this.notionRepository.deleteNotionData(owner);
}
}

0 comments on commit 22d16d3

Please sign in to comment.