Skip to content

Commit

Permalink
Merge pull request #921 from SeedCompany/917-create-project-duplicati…
Browse files Browse the repository at this point in the history
…on-error

Throw duplication exception while creating with same project name
  • Loading branch information
michaelmarshall authored Aug 10, 2020
2 parents cd822c5 + 3bcc0c1 commit 57372fc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/components/engagement/engagement.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,12 @@ export class EngagementService {
// Initial LanguageEngagement
const id = generate();
const createdAt = DateTime.local();
const pnp = await this.files.createDefinedFile(`PNP`, session, input.pnp, 'engagement.pnp');
const pnp = await this.files.createDefinedFile(
`PNP`,
session,
input.pnp,
'engagement.pnp'
);

const ceremony = await this.ceremonyService.create(
{ type: CeremonyType.Dedication },
Expand Down Expand Up @@ -1016,7 +1021,12 @@ export class EngagementService {
session
)) as LanguageEngagement;

await this.files.updateDefinedFile(object.pnp, 'engagement.pnp', pnp, session);
await this.files.updateDefinedFile(
object.pnp,
'engagement.pnp',
pnp,
session
);

try {
await this.db.sgUpdateProperties({
Expand Down Expand Up @@ -1060,7 +1070,12 @@ export class EngagementService {
session
)) as InternshipEngagement;

await this.files.updateDefinedFile(object.growthPlan, 'engagement.growthPlan', growthPlan, session);
await this.files.updateDefinedFile(
object.growthPlan,
'engagement.growthPlan',
growthPlan,
session
);

try {
if (mentorId) {
Expand Down Expand Up @@ -1161,10 +1176,7 @@ export class EngagementService {
throw new ServerException('Could not find update InternshipEngagement');
}

return (await this.readOne(
input.id,
session
)) as InternshipEngagement;
return (await this.readOne(input.id, session)) as InternshipEngagement;
}

// DELETE /////////////////////////////////////////////////////////
Expand Down
8 changes: 8 additions & 0 deletions src/components/project/project.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { node, relation } from 'cypher-query-builder';
import { flatMap, upperFirst } from 'lodash';
import { DateTime } from 'luxon';
import {
DuplicateException,
fiscalYears,
InputException,
ISession,
Expand All @@ -29,6 +30,7 @@ import {
OnIndex,
Property,
runListQuery,
UniquenessError,
} from '../../core';
import {
Budget,
Expand Down Expand Up @@ -375,6 +377,12 @@ export class ProjectService {

return project;
} catch (e) {
if (e instanceof UniquenessError && e.label === 'ProjectName') {
throw new DuplicateException(
'project.name',
'Project with this name already exists'
);
}
this.logger.warning(`Could not create project`, {
exception: e,
});
Expand Down

0 comments on commit 57372fc

Please sign in to comment.