Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[2/2] Affiliate program Integration v1 (podkrepi-bg#564)
Affiliate Program integration All changes below: * auth: Allow for corporate registrations The corporate registrations will be manually verified, and activated by podkrepi.bg administrator. * auth: Don't create new corporate profile if company exists * Affiliate Program: Initial changes -Added Affiliate model -Removed company field from Person model. That information will now be received from the company relation -Added endpoints to handle adding new affiliates, and updating their status * Run prisma migrate * schema.prisma: Add donation relation to Affiliate model * schema.prisma: Add guaranteed status for donations * Add affiliateId to testing and seeding scripts * validation: Set exposeDefaultValues to true globally Would allow us to set default values to fields directly in the dto, which might result in cleaner code. * src/affiliate: Implement endpoints for creating/cancelling donations Affiliate donations will be marked as guaranteed by default * src/campaign: Include guaranteedAmount in campaign's summary * tasks/bank-import: Handle affiliate donations * bank-transactions: Add endpoint to simulate IRIS transactions. Available only on development/staging enviroment * src/affiliate: Change affiliateCode structure * affiliate: Make affiliateCode available only for active affiliates * jest: Fix test breakage * src/donations: Include guaranteed donations in listPublic Removed unnecessary count query. Replaced with the length of the findMany query * eslint: Address errors and warnings * src/donations: Include companyName in listPublic endpoint * corporateUser: Add space between first and last name for legalpersonname * src/affiliate: Generate new code whenever affiliate is set to active * Run nx format * src/donations:c Add affiliateId to donation mock * src/affiliates: Add tests * bank-transaction: Return unprocessed if no guaranteed donations are found for affiliate * tasks/bank-import: Set transaction to importFailed if no guaranteed donations are found for affiliate * tasks/bank-import: Include test for affiliate donations * src/affiliate: Fix redundant space on ForbiddenException * affiliate.controller.spec: Rename test to AffiliateController * schema.prisma: Add companyId to person model * auth.service: Add companyId in createPerson method * src/register.controller: Use single endpoint for registration - Removed CompanyRegisterDto, and moved companyNumber and companyName to RegisterDto. - Added type to RegisterDto, to differentiate individual/corporate profiles - Made it so companyName and companyNumber fields will be validated only if profile's type is corporate * Consider bank transaction as successfull if no guaranteed donations are found * affiliate: Rename endpoints * bank-transaction: Update bankDonationStatus on duplicate record * affiliate: Create endpoint to get donations with pagination * schema.prisma:Affiliate: Make companyId not null * affiliateCodeGenerator: Get the first 8 characters * eslint: Address error and warnings * tasks/bank-import: Change bankstatus only if donation is affiliate * jest: Fix tests * swagger: Provide schema for iris-transaction-test endpoint * bank-import: Initialize variable with affiliate code prefix * donation: Add metadata field to donation Model Similar to how metadata field works in Stripe, this field will include additional data, for the donation, such as the name of the person who donated through the affiliate API, and additional field to store necessary for the affiliate data. * schema.prisma: Map DonationMetadata model * src/affiliate: Include metadata in affiliateDonationDto in jest * src/auth: Allow for corporate fields to be either string or undefined * src/affiliate: Improve semantics CreateAffiliateDonationDto: Removed validator decorators from affiliateId, personId, billingName and billigEmail, as those fields shouldn't be part of the request body itself. createAffiliateDonation(): Use chain conditioning to find whether affiliate exists or not. * src/affiliate: Fix test * src/affiliate: Include JWT_SECRET_KEY when generating affiliate code When generating affiliate code using only affiliateId, the affiliate code could easily be leaked, if some API response returns the affiliateId. This change ensures that this doesn't happen * src/affiliate: Create new endpoint to refresh affiliate code Would be useful in case of a leak * src/donations: Fix error handling if no vault has been found vaultService.findByCampaignId returns an array, thus we need to also check if the length of that array is 0 * src/affiliate: Check whether campaign accepts more donations before making one * src/donations: Bring back count query to listPublic service endpoint The result of donation's query is paginated, thus its length doesnt represent the total amount of donations, and thus breaks the pagination on the front-end * src/donations: Handle corporate donations * src/donations: Don't update updatedAt property on imported donation When we show the donations on frontend they are ordered by the updatedAt property in descending order, thus when bank transaction is imported, those affiliate donations will be shown again on top of the list, which might cause confusion * src/donation-wish: Extend selector to include companyName and donation type * src/affiliate: Include donation wish in query * updateAffiliateBankPayment: Use value of donation's updatedAt field When passing undefined to the query, prisma still updates the updatedAt field, as it uses default property * getUserDonationById: Include companyName inside the query Needed in order to show the corporation's name inside the certificate * userDonationById(): Get first and last name from keycloak token Needed in order to show the name of the donor on the certificate, if the donation is anonymous * src/affiliate: Add new endpoint to get affiliate's data by userid * src/affiliate: cleanup console.log * schema.prisma: Add profileEnabled to person table Makes it easier to track whether a corporate profile is enabled or not * src/account: Make endpoint for manual activation/deactivation of profile * src/person: Fix ordering by profile type not working * src/auth: Prevent deactivation of profile if it is in podkrepi-admin group * src/affiliate: Solve ts errors on controller.spec * src/affiliate: Add new endpoint to list all affiliates Needed for the admin panel * src/affiliate: Include person's email in findAll query result * src/auth: Fix test breakage * schema.prisma: Add createdAt and updatedAt fields to Affiliate model * src/donations: Improve validation of metadata fields if not undefined -if metadata is included in the request body -it should not be empty -should contain either name or extraData -extraData should be an object * src/donations: Fix ts errors * bank-transaction: iris-simulation should be done only by admin * dto/donation-metadata: Fix extraData field being empty on valid Object being sent Apparently the latest changes broke the extraData field. - Removed the unecessary dto extension, as it is enough to validated whether the extraData is Object - Used more specific type of the expected request body of extraData * src/auth: Change admin roles lookup In keycloak admin access is granted through team-support role - which is compose of view-supporters, view-contact-requests. * events/stripe: Resolve errors after merge of master * ESLint: Remove unused imports * auth.service.spec: Bring back issueToken testcase Not quite sure why it was removed
- Loading branch information