Skip to content

SudoSOS Back-end API / helpers

Helpers ​

This is the module page of the ad.

Enumerations ​

EnumerationDescription
OrderingDirection-
ReturnFileTypeFile type a PDF-able document can be returned as: the compiled PDF, or the raw HTML that is sent to pdf-compiler (useful for previews and debugging).
UserReportTypeEnum for the type of user report (sales or purchases).

Classes ​

ClassDescription
QueryFilter-
ValidationErrorThe ValidationError combines itself by simply concatenating the string values.

Interfaces ​

InterfaceDescription
FilterMappingDefines the mapping from properties on the parameter object, to the respective identifiers in queries.
FilterParametersDefines the filtering parameters to which can be mapped.
ImageValidationRequirements-
IReportDocumentLines-
JoinableTo allow for nested errors we need the notation of traversing through errors. The abstraction is that we have a 'Joinable' such that items can be combined.
LDAPGroup-
LDAPResponse-
LDAPResult-
LDAPUser-
PaginationParameters-
PaginationResult-
RawUser-
RequestWithRawBodyExtend the Express Request object with a raw body attribute, which is used by Stripe to validate incoming events

Type Aliases ​

Type AliasDescription
Either-
Fail-
ImageType-
Optional-
Pass-
Specification-
SubSpecification-
ValidationRule-

Variables ​

VariableDescription
ALLOWED_IMAGE_FORMATS-
IMAGE_FORMAT_EXTENSIONSFile extension used to store an image, keyed by the format sharp detects from the file contents.
IMAGE_REQUIREMENTS-
PAGINATION_DEFAULT-
PAGINATION_MAX-
PDF_VAT_HIGH-
PDF_VAT_LOW-
PDF_VAT_ZERO-
PERSISTENT_TEST_DATABASES-

Functions ​

FunctionDescription
asArrayOfDatesConverts the input to a list of dates
asArrayOfNumbersConverts the input to a list of numbers
asArrayOfUserTypesConverts the input to a list of UserTypes
asBooleanConverts the input to a boolean
asDateConverts the input to a Date object.
asDineroConverts the input to a Dinero object.
asEventTypeConverts the input to an EventType
asFromAndTillDateConverts the inputs to a from and till date
asInvoiceStateConverts the input to a InvoiceState
asNumberConverts the input to a number.
asOrderingDirectionConvert the given input to an OrderingDirection object or undefined if correct. Throw error otherwise
asReturnFileTypeConverts the input to a ReturnFileType. Defaults to PDF when no input is given.
asShiftAvailabilityConverts the input to a shift availability
asUserTypeConverts the input to a UserType
asVatDeclarationPeriodConverts the input to an VatDeclarationPeriod
bindUserFunction that takes a valid ADUser response and binds it to a existing User such that the AD user can authenticate as the existing user.
collectByKeyFunction that collects items based on a given getKey function
collectByToIdFunction that collects transaction by user ToId
collectProductsByCategoryFunction that collects transactions by product based on their category id
collectProductsByRevisionFunction that collects transactions by products based on their revision
collectProductsByVatFunction that collects transactions by product based on their Vat group
createArrayRuleTurn a specification for an property into a specification for an array of that property.
dateToUTCChange the timezone of the given date to UTC
defaultPagination-
extractRawBodyPut the raw, unparsed body also in the request object
formatTitleDateFormat a date to YYYYMMDD string format for use in PDF filenames and titles
getIdsAndRequests-
getLDAPConnectionMakes and bind an LDAP connection.
getLDAPSettingsWrapper for the LDAP environment variables.
hashJSONReturns the sha256 hash of an object.
isDateReturns whether a given date string is actually a date
isFail-
isNumberReturns whether the given object is a number
isPass-
maxPagination-
parseContainerToBaseResponse-
parseFileToResponse-
parseInvoiceUserToResponse-
parsePOSToBasePOS-
parseProductToBaseResponse-
parseRawUserToResponseParses a raw User Entity to a UserResponse
parseRequestPaginationExtract possible pagination parameters from the request and put them in the take and skip variables. If one of them (or all of them) is not defined, default values are set.
parseUserToBaseResponseParses a raw user DB object to BaseUserResponse
parseUserToResponseParses a User DB entity to a UserResponse
parseVatGroupToResponse-
reduceMapToCategoryEntriesTransforms an array of SubTransactionRows with the same product category into TransactionReportCategoryEntries
reduceMapToReportEntriesTransforms an array of SubTransactionRows of a single product to TransactionReportEntries
reduceMapToVatEntriesTransforms an array of SubTransactionRows with the same VAT group into TransactionReportVatEntries
reportPDFhelper-
reportToDocumentLinesMap a report's products and VAT groups onto the line items, VAT specification and totals of the shared HTML document (euros, not cents).
sendPdfOrHtmlSend a rendered document as an attachment with the content type and extension that match its file type.
splitTypes-
toFail-
toLocalMySQLStringPrint the date to a string in MySQL format (YYYY-MM-DD mm:hh:ss), but keep it in the local timezone
toMySQLStringPrint the date to a string in MySQL format (YYYY-MM-DD mm:hh:ss)
toPass-
toResponseBuild a paginated response from a [records, count] tuple. Use this in controllers to wrap service results into the standard paginated response format.
toUTCMySQLStringPrint the date to a string in MySQL format (YYYY-MM-DD mm:hh:ss), but convert it to UTC
transactionMapperApplies a function to all SubTransactionRows of the given transactions.
userFromLDAPWrapper for typing the untyped ldap result.
userTokenInOrganChecks if the given ID is part of the Token Organ List.
utcToDateUTC to date
validateImageUploadValidate an uploaded image against the requirements of the given image type.
validateRequestPaginationCheck whether the possible take and skip query parameters are valid
validateSpecificationFunction that validates the given param against a specification.