-
-
Notifications
You must be signed in to change notification settings - Fork 227
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 #723 from bigcapitalhq/invoice-mail-receipt
feat: wip Invoice mail receipt preview
- Loading branch information
Showing
86 changed files
with
12,237 additions
and
2,781 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,46 @@ | ||
import { isEmpty } from 'lodash'; | ||
import { castArray, isEmpty } from 'lodash'; | ||
import { ServiceError } from '@/exceptions'; | ||
import { CommonMailOptions, CommonMailOptionsDTO } from '@/interfaces'; | ||
import { CommonMailOptions } from '@/interfaces'; | ||
import { ERRORS } from './constants'; | ||
|
||
/** | ||
* Merges the mail options with incoming options. | ||
* @param {Partial<SaleInvoiceMailOptions>} mailOptions | ||
* @param {Partial<SendInvoiceMailDTO>} overridedOptions | ||
* @throws {ServiceError} | ||
*/ | ||
export function parseAndValidateMailOptions( | ||
mailOptions: Partial<CommonMailOptions>, | ||
overridedOptions: Partial<CommonMailOptionsDTO> | ||
) { | ||
export function parseMailOptions( | ||
mailOptions: CommonMailOptions, | ||
overridedOptions: Partial<CommonMailOptions> | ||
): CommonMailOptions { | ||
const mergedMessageOptions = { | ||
...mailOptions, | ||
...overridedOptions, | ||
}; | ||
if (isEmpty(mergedMessageOptions.from)) { | ||
const parsedMessageOptions = { | ||
...mergedMessageOptions, | ||
from: mergedMessageOptions?.from | ||
? castArray(mergedMessageOptions?.from) | ||
: [], | ||
to: mergedMessageOptions?.to ? castArray(mergedMessageOptions?.to) : [], | ||
cc: mergedMessageOptions?.cc ? castArray(mergedMessageOptions?.cc) : [], | ||
bcc: mergedMessageOptions?.bcc ? castArray(mergedMessageOptions?.bcc) : [], | ||
}; | ||
return parsedMessageOptions; | ||
} | ||
|
||
export function validateRequiredMailOptions( | ||
mailOptions: Partial<CommonMailOptions> | ||
) { | ||
if (isEmpty(mailOptions.from)) { | ||
throw new ServiceError(ERRORS.MAIL_FROM_NOT_FOUND); | ||
} | ||
if (isEmpty(mergedMessageOptions.to)) { | ||
if (isEmpty(mailOptions.to)) { | ||
throw new ServiceError(ERRORS.MAIL_TO_NOT_FOUND); | ||
} | ||
if (isEmpty(mergedMessageOptions.subject)) { | ||
if (isEmpty(mailOptions.subject)) { | ||
throw new ServiceError(ERRORS.MAIL_SUBJECT_NOT_FOUND); | ||
} | ||
if (isEmpty(mergedMessageOptions.body)) { | ||
if (isEmpty(mailOptions.message)) { | ||
throw new ServiceError(ERRORS.MAIL_BODY_NOT_FOUND); | ||
} | ||
return mergedMessageOptions; | ||
} |
Oops, something went wrong.