diff --git a/libs/api/onboarding-api/feature-account/src/lib/services/link.service.ts b/libs/api/onboarding-api/feature-account/src/lib/services/link.service.ts
index 73631372..99b68f86 100644
--- a/libs/api/onboarding-api/feature-account/src/lib/services/link.service.ts
+++ b/libs/api/onboarding-api/feature-account/src/lib/services/link.service.ts
@@ -19,7 +19,15 @@ export class LinkService {
async createLinkAndSendEmail(fullLink: LinkEntity, sendEmail: boolean) {
return getManager().transaction(async manager => {
+ const oldInvites = await manager.getRepository(LinkEntity).find({
+ where: { email: fullLink.email },
+ });
+ // if the user repeatedly sends invite reuqests, we want the last one to be valid
+ oldInvites.forEach(async request => {
+ await manager.getRepository(LinkEntity).save({ ...request, status: StatusType.INACTIVE });
+ });
const createdLink = await manager.getRepository(LinkEntity).save(fullLink);
+
if (sendEmail) {
try {
await this.emailService.sendInvitationEmail(createdLink);
@@ -54,10 +62,6 @@ export class LinkService {
fullLink.project = projectEntity;
// Check link email does not already exist
- const existingLink = await this.linkRepository.findOne({ where: { email: link.email } });
- if (existingLink) {
- throw new BadRequestException(`Link for email ${link.email} already exists`);
- }
const createdLink = await this.createLinkAndSendEmail(fullLink, sendEmail);
diff --git a/libs/api/onboarding-api/feature-account/src/lib/services/resource.service.ts b/libs/api/onboarding-api/feature-account/src/lib/services/resource.service.ts
index b0c03a23..4bee815d 100644
--- a/libs/api/onboarding-api/feature-account/src/lib/services/resource.service.ts
+++ b/libs/api/onboarding-api/feature-account/src/lib/services/resource.service.ts
@@ -162,7 +162,7 @@ export class ResourceService {
return projects;
}
- async getProjResourcesMatchingFilter(filter: string): Promise {
+ async getProjResourcesMatchingFilter(filter: string): Promise {
const projWithFilter = await this.getProjectWithMatchingFilter(filter);
const projIds = projWithFilter.map(proj => proj.id);
@@ -180,7 +180,17 @@ export class ResourceService {
{ query: `%${filter}%`, projIds },
)
.getMany();
- return projResourcesMatchingFilter;
+
+ const resources = projResourcesMatchingFilter.map(projRes => projRes.resource);
+ // maybe searching for an unassigned resource
+ const unassignedResourceFilter = await this.resourceRepository
+ .createQueryBuilder('resource')
+ .where(`CONCAT("resource"."firstName", ' ', "resource"."lastName") like :query`, {
+ query: `%${filter}%`,
+ })
+ .getMany();
+
+ return [...resources, ...unassignedResourceFilter];
}
async getAllResourceProjectInfo(
@@ -194,10 +204,9 @@ export class ResourceService {
let resourcesAndCount: [ResourceEntity[], number] = [[], 0];
const whereClause: FindConditions = {};
-
if (filter !== '') {
const projResources = await this.getProjResourcesMatchingFilter(filter);
- const resMatchingFilterIds = Array.from(new Set(projResources.map(projRes => projRes.resource.id)));
+ const resMatchingFilterIds = Array.from(new Set(projResources.map(resource => resource.id)));
whereClause.id = In(resMatchingFilterIds);
}
if (roleType && roleType.length > 0) {
diff --git a/libs/api/onboarding-api/feature-account/src/lib/tests/services/link.service.spec.ts b/libs/api/onboarding-api/feature-account/src/lib/tests/services/link.service.spec.ts
index f1e8c307..ffdf0e15 100644
--- a/libs/api/onboarding-api/feature-account/src/lib/tests/services/link.service.spec.ts
+++ b/libs/api/onboarding-api/feature-account/src/lib/tests/services/link.service.spec.ts
@@ -184,19 +184,6 @@ describe('LinkService', () => {
expect(mockLinkRepository.save).not.toBeCalled();
});
- it('should throw an error if link email already exists', async () => {
- let error;
- mockLinkRepository.findOne.mockResolvedValue(createLinkEntity);
- try {
- await linkService.createLink(businessOwnerJwtPayload, createLinkEntity, 1);
- } catch (e) {
- error = e;
- }
- expect(error).toBeInstanceOf(BadRequestException);
- expect(error.message).toBe('Link for email test@email.com already exists');
- expect(mockLinkRepository.save).not.toBeCalled();
- });
-
it('should only email the link if saving is successful', async () => {
mockLinkRepository.save.mockRejectedValue(new Error('db constraint'));
mockLinkRepository.findOne.mockResolvedValue(undefined);
diff --git a/libs/api/shared/api-assets/src/lib/images/CAL-Logo.png b/libs/api/shared/api-assets/src/lib/images/CAL-Logo.png
new file mode 100644
index 00000000..4db2ef32
Binary files /dev/null and b/libs/api/shared/api-assets/src/lib/images/CAL-Logo.png differ
diff --git a/libs/api/shared/api-assets/src/lib/templates/email/accountDeleted.hbs b/libs/api/shared/api-assets/src/lib/templates/email/accountDeleted.hbs
index c3f9295b..63eb5ef1 100644
--- a/libs/api/shared/api-assets/src/lib/templates/email/accountDeleted.hbs
+++ b/libs/api/shared/api-assets/src/lib/templates/email/accountDeleted.hbs
@@ -12,7 +12,7 @@
Best,
CAL & Associates
-
+