This repository has been archived by the owner on Aug 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #422 from beabee-communityrm/feat/delete-contact
feat: add delete contact endpoint
- Loading branch information
Showing
24 changed files
with
345 additions
and
86 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
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
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,55 @@ | ||
import { getRepository } from "@core/database"; | ||
import { generateApiKey } from "@core/utils/auth"; | ||
|
||
import ApiKey from "@models/ApiKey"; | ||
import Contact from "@models/Contact"; | ||
|
||
class ApiKeyService { | ||
/** | ||
* Create a new API key | ||
* @param creator The contact that created the API key | ||
* @param description A description of the API key | ||
* @param expires When the API key expires, or null if it never expires | ||
* @returns the new API key token | ||
*/ | ||
async create( | ||
creator: Contact, | ||
description: string, | ||
expires: Date | null | ||
): Promise<string> { | ||
const { id, secretHash, token } = generateApiKey(); | ||
|
||
await getRepository(ApiKey).save({ | ||
id, | ||
secretHash, | ||
creator, | ||
description, | ||
expires | ||
}); | ||
|
||
return token; | ||
} | ||
|
||
/** | ||
* Delete an API key | ||
* @param id The API key ID | ||
* @returns Whether the API key was deleted | ||
*/ | ||
async delete(id: string): Promise<boolean> { | ||
const res = await getRepository(ApiKey).delete({ id }); | ||
return !!res.affected; | ||
} | ||
|
||
/** | ||
* Permanently disassociate an API key from a contact | ||
* @param contact The contact | ||
*/ | ||
async permanentlyDeleteContact(contact: Contact) { | ||
await getRepository(ApiKey).update( | ||
{ creatorId: contact.id }, | ||
{ creatorId: null } | ||
); | ||
} | ||
} | ||
|
||
export default new ApiKeyService(); |
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
Oops, something went wrong.