-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#3169 getparttags endpoint #3207
base: feature/cad-project-file-review
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -407,4 +407,31 @@ export default class OrganizationsService { | |
|
||
return updatedOrg; | ||
} | ||
|
||
/** | ||
* Uses the given organizationID to and returns an array of part tags | ||
* @param organizationId the organization to get the parts for | ||
* @returns an array of part tags | ||
*/ | ||
static async getAllPartTags(organizationId: string) { | ||
const organization = await prisma.organization.findUnique({ | ||
where: { organizationId } | ||
}); | ||
|
||
if (!organization) { | ||
throw new NotFoundException('Organization', organizationId); | ||
} | ||
|
||
return prisma.partTag.findMany({ | ||
where: { organizationId }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only return partTags where dateDeleted is null |
||
select: { | ||
partTagId: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't need to include partTagId: true here |
||
parts: { | ||
select: { | ||
partId: true | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { NotFoundException } from '../../src/utils/errors.utils'; | ||
import OrganizationsService from '../../src/services/organizations.services'; | ||
import { createTestOrganization, resetUsers } from '../test-utils'; | ||
import prisma from '../../src/prisma/prisma'; | ||
import { Organization } from '@prisma/client'; | ||
|
||
describe('Get All Part Tags', () => { | ||
let organizationID: string; | ||
let organization: Organization; | ||
|
||
beforeEach(async () => { | ||
organization = await createTestOrganization(); | ||
organizationID = organization.organizationId; | ||
await prisma.partTag.deleteMany(); | ||
}); | ||
|
||
afterEach(async () => { | ||
await resetUsers(); | ||
}); | ||
|
||
it('Fails if organization does not exist', async () => { | ||
await expect(OrganizationsService.getAllPartTags('no-id')).rejects.toThrow( | ||
new NotFoundException('Organization', 'no-id') | ||
); | ||
}); | ||
|
||
it('Succeeds and returns empty array', async () => { | ||
const partTags = await OrganizationsService.getAllPartTags(organizationID); | ||
expect(partTags).toBeInstanceOf(Array); | ||
expect(partTags.length).toEqual(0); | ||
}); | ||
|
||
it('Succeeds and returns part tags', async () => { | ||
await prisma.partTag.createMany({ | ||
data: [ | ||
{ | ||
partTagId: '123', | ||
name: 'Screw', | ||
colorHexCode: '#191010', | ||
dateCreated: new Date(), | ||
organizationId: organizationID | ||
}, | ||
{ partTagId: '456', name: 'Bolt', colorHexCode: '#093121', dateCreated: new Date(), organizationId: organizationID } | ||
] | ||
}); | ||
|
||
const partTags = await OrganizationsService.getAllPartTags(organizationID); | ||
expect(partTags.length).toEqual(2); | ||
expect(partTags.some((tag) => tag.partTagId === '123')).toBeTruthy(); | ||
expect(partTags.some((tag) => tag.partTagId === '456')).toBeTruthy(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a partTag to a different organization, and a partTag that is deleted, and check that these are not in the result |
||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Organization } from './user-types'; | ||
|
||
export interface PartTagReviewType { | ||
partTagId: string; | ||
name: string; | ||
colorHexCode: string; | ||
dateCreated: Date; | ||
dateDeleted?: Date; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't include dateDeleted in the shared type. If it was deleted, people should not be seeing it on the frontend |
||
parts: String[]; | ||
organization?: Organization; | ||
organizationId: string; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the organization is pulled from the request and not an input from the user, you don't need to check for a notFoundException here. If the organization id for whatever reason did not exist here, it would be a problem on our end not the requester's end. Instead you can just get rid of this check