Skip to content

Commit

Permalink
feat(mailaddress-model): add create and createForward functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ntdoJanneck committed Oct 25, 2024
1 parent 8d0fe12 commit 4623905
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
31 changes: 31 additions & 0 deletions packages/models/src/mail/MailAddress/MailAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,37 @@ export class MailAddress extends ReferenceModel {
MailAddress.find(this.id),
) as AsyncResourceVariant<() => Promise<MailAddressDetailed | undefined>>;

public static async create(
projectId: string,
mailAddress: string,
password: string,
isCatchAll: boolean,
enableSpamProtection: boolean,
quotaInBytes: number,
): Promise<MailAddress> {
const { id } = await config.behaviors.mailAddress.create(
projectId,
mailAddress,
password,
isCatchAll,
enableSpamProtection,
quotaInBytes,
);
return new MailAddress(id);
}

public static async createForward(
projectId: string,
address: string,
forwardAddresses: string[],
): Promise<MailAddress> {
const { id } = await config.behaviors.mailAddress.createForward(
projectId,
address,
forwardAddresses,
);
return new MailAddress(id);
}
public async updateAddress(address: string): Promise<void> {
await config.behaviors.mailAddress.updateAddress(this.id, address);
}
Expand Down
24 changes: 24 additions & 0 deletions packages/models/src/mail/MailAddress/behaviors/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,29 @@ export const apiMailAddressBehaviors = (
assertStatus(response, 204);
},
create: async (
projectId: string,
mailAddress: string,
password: string,
isCatchAll: boolean,
enableSpamProtection: boolean,
quotaInBytes: number,
) => {
const response = await client.mail.createMailAddress({
projectId,
data: {
isCatchAll,
address: mailAddress,
mailbox: {
enableSpamProtection,
password,
quotaInBytes,
},
},
});
assertStatus(response, 201);
return response.data;
},
createForward: async (
projectId: string,
address: string,
forwardAddresses: string[],
Expand All @@ -38,6 +61,7 @@ export const apiMailAddressBehaviors = (
data: { address, forwardAddresses },
});
assertStatus(response, 201);
return response.data;
},
updateAddress: async (mailAddressId: string, address: string) => {
const response = await client.mail.updateMailAddressAddress({
Expand Down
10 changes: 9 additions & 1 deletion packages/models/src/mail/MailAddress/behaviors/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@ export interface MailAddressBehaviors {
delete: (mailAddressId: string) => Promise<void>;

create: (
projectId: string,
mailAddress: string,
password: string,
isCatchAll: boolean,
enableSpamProtection: boolean,
quotaInBytes: number,
) => Promise<{ id: string }>;
createForward: (
projectId: string,
address: string,
forwardAddresses: string[],
) => Promise<void>;
) => Promise<{ id: string }>;

updateAddress: (mailAddressId: string, address: string) => Promise<void>;
updatePassword: (mailAddressId: string, password: string) => Promise<void>;
Expand Down

0 comments on commit 4623905

Please sign in to comment.