Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export class ResourceService {
return projects;
}

async getProjResourcesMatchingFilter(filter: string): Promise<ProjectResourceEntity[]> {
async getProjResourcesMatchingFilter(filter: string): Promise<ResourceEntity[]> {
const projWithFilter = await this.getProjectWithMatchingFilter(filter);
const projIds = projWithFilter.map(proj => proj.id);

Expand All @@ -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(
Expand All @@ -194,10 +204,9 @@ export class ResourceService {
let resourcesAndCount: [ResourceEntity[], number] = [[], 0];

const whereClause: FindConditions<ResourceEntity> = {};

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</p>
<p>Best,</p>
<p>CAL & Associates</p>
<img src='CalLogo:imgID' alt='Cal & Associates Logo' />
<img src='cid:CAL-Logo' alt='Cal & Associates Logo' />
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<br />
<p>Best,</p>
<p>CAL & Associates</p>
<img src='CalLogo:imgID' alt='Cal & Associates Logo' />
<img width='80' src='cid:CAL-Logo' alt='Cal & Associates Logo' />
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<body>
<h3>Hello {{name}}, </h3>
<div>
<p>You have been assigned the role of Business Owner for the Tempus Application. Please set your password using this
<p>You have been assigned the role of Business Owner for the Tempus Application. Please set your password
using this
<a href='{{url}}{{code}}'>link</a>
</p>
<p>
Expand All @@ -14,7 +15,7 @@
<br />
<p>Best,</p>
<p>CAL & Associates</p>
<img src='CalLogo:imgID' alt='Cal & Associates Logo' />
<img width='80' src='cid:CAL-Logo' alt='Cal & Associates Logo' />
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<body>
<h3>Hello {{name}}, </h3>
<div>
<p>You have been assigned the role of supervisor for the Tempus Application. Please set your password using this
<p>You have been assigned the role of supervisor for the Tempus Application. Please set your password using
this
<a href='{{url}}{{code}}'>link</a>
</p>
<p>
Expand All @@ -14,7 +15,7 @@
<br />
<p>Best,</p>
<p>CAL & Associates</p>
<img src='CalLogo:imgID' alt='Cal & Associates Logo' />
<img width='80' src='cid:CAL-Logo' alt='Cal & Associates Logo' />
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
<body>
<h3>Hello {{name}}, </h3>
<div>
<p>Please reset your password using <a href="{{url}}{{code}}">this link.</a>
<p>Please reset your password using
<a href='{{url}}{{code}}'>this link.</a>
</p>
<p>
The link will expire by
<b>{{expiry}}</b>. If you need any help throughout the proccess, please contact
<a href='mailto:admin@cal.com'>admin@cal.com.</a>
</p>
<p>
If you did not request to reset your password, ignore this message.
<p>
If you did not request to reset your password, ignore this message.
</p>
<br />
<p>Best,</p>
<p>CAL & Associates</p>
<img src='CalLogo:imgID' alt='Cal & Associates Logo' />
<img src='cid:CAL-Logo' alt='Cal & Associates Logo' />
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class LinkEntity implements Link {
@Column()
lastName: string;

@Column({ unique: true })
@Column()
email: string;

@Column()
Expand Down
30 changes: 18 additions & 12 deletions libs/api/shared/feature-email/src/lib/services/email.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { MailerService } from '@nestjs-modules/mailer';
import { LinkEntity, PasswordResetEntity, UserEntity } from '@tempus/api/shared/entity';
import { ConfigService } from '@nestjs/config';
import { RoleType } from '@tempus/shared-domain';
import path = require('path');

@Injectable()
export class EmailService {
Expand All @@ -25,14 +26,13 @@ export class EmailService {
name: `${link.firstName} ${link.lastName}`,
expiry: new Date(link.expiry).toLocaleDateString(),
},
// TODO: uncomment me when the next version of nestmailer is released
/* attachments: [
attachments: [
{
filename: 'placeholder.png',
path: path.resolve(`${__dirname}/assets/images/`),
cid: 'CalLogo:imgID', // same cid value as in the html img src
filename: 'CAL-Logo.png',
path: path.resolve(`${__dirname}/assets/images/CAL-Logo.png`),
cid: 'CAL-Logo', // same cid value as in the html img src
},
], */
],
});
}

Expand All @@ -48,14 +48,13 @@ export class EmailService {
name: `${passwordResetDetails.user.firstName} ${passwordResetDetails.user.lastName}`,
expiry: new Date(passwordResetDetails.expiry).toLocaleDateString(),
},
// TODO: uncomment me when the next version of nestmailer is released
/* attachments: [
attachments: [
{
filename: 'placeholder.png',
path: path.resolve(`${__dirname}/assets/images/`),
cid: 'CalLogo:imgID', // same cid value as in the html img src
filename: 'CAL-Logo.png',
path: path.resolve(`${__dirname}/assets/images/CAL-Logo.png`),
cid: 'CAL-Logo', // same cid value as in the html img src
},
], */
],
});
}

Expand All @@ -69,6 +68,13 @@ export class EmailService {
context: {
name: `${user.firstName} ${user.lastName}`,
},
attachments: [
{
filename: 'CAL-Logo.png',
path: path.resolve(`${__dirname}/assets/images/CAL-Logo.png`),
cid: 'CAL-Logo', // same cid value as in the html img src
},
],
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class CreateProjectModalComponent implements OnInit {
prefix = 'modal.newProjectModal.';

statusOptions = [
{ val: 'Not Started', id: 'not_started' },
{ val: 'Not Started', id: 'Not Started' },
{ val: 'Active', id: 'active' },
{ val: 'Completed', id: 'completed' },
];
Expand Down
Binary file modified libs/client/shared/ui-assets/src/favicon.ico
Binary file not shown.
14 changes: 14 additions & 0 deletions migrations/1670453834137-Allow duplicate emails for link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {MigrationInterface, QueryRunner} from "typeorm";

export class AllowDuplicateEmailsForLink1670453834137 implements MigrationInterface {
name = 'AllowDuplicateEmailsForLink1670453834137'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "link_entity" DROP CONSTRAINT "UQ_9457468f6bf7dbf40ee7d1e4214"`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "link_entity" ADD CONSTRAINT "UQ_9457468f6bf7dbf40ee7d1e4214" UNIQUE ("email")`);
}

}
Loading