-
Notifications
You must be signed in to change notification settings - Fork 35
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
chore: create project personnel #1796
Changes from 8 commits
1d9a154
a699600
f1a6eae
b2963fd
1240a6a
da24b77
ad7da0c
e019ba5
3f28a86
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import crypto from 'crypto' | ||
|
||
import PersonnelModel, { PersonnelAttributes } from '../back/models/Personnel' | ||
import ProjectModel, { ProjectAttributes } from '../back/models/Project' | ||
import { TransparencyVesting } from '../clients/Transparency' | ||
import UnpublishedBidModel from '../entities/Bid/model' | ||
import { BidProposalConfiguration } from '../entities/Bid/types' | ||
import { GrantTier } from '../entities/Grant/GrantTier' | ||
import { GRANT_PROPOSAL_DURATION_IN_SECONDS } from '../entities/Grant/constants' | ||
import { GrantRequest, ProjectStatus, TransparencyProjectStatus } from '../entities/Grant/types' | ||
|
@@ -164,20 +166,46 @@ export class ProjectService { | |
} | ||
|
||
private static async createProject(proposal: ProposalWithOutcome) { | ||
const newProject: ProjectAttributes = { | ||
const creationDate = new Date() | ||
const newProject = await ProjectModel.create({ | ||
id: crypto.randomUUID(), | ||
proposal_id: proposal.id, | ||
title: proposal.title, | ||
status: ProjectStatus.Pending, | ||
links: [], | ||
created_at: new Date(), | ||
} | ||
created_at: creationDate, | ||
}) | ||
|
||
await ProjectService.createPersonnel(proposal, newProject, creationDate) | ||
|
||
return await ProjectModel.create(newProject) | ||
return newProject | ||
} | ||
|
||
private static async createPersonnel( | ||
proposal: ProposalWithOutcome, | ||
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. We don't we pass just 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. I was looking at it as if finding/parsing the info needed to create the personnel was part of this method's responsibility (so |
||
newProject: ProjectAttributes, | ||
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. This won't be always a new project, isn't it? Maybe we can call it 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. Hmm I agree on the name change, but in this case we will always use a new project, since the If we want to create new personnel for a project that already exists, we should have another method that creates them one by one (this one uses WDYT? |
||
creationDate: Date | ||
) { | ||
const newPersonnel: PersonnelAttributes[] = [] | ||
const config = | ||
proposal.type === ProposalType.Grant | ||
? (proposal.configuration as GrantProposalConfiguration) | ||
: (proposal.configuration as BidProposalConfiguration) | ||
config.members?.forEach((member) => { | ||
if (member) { | ||
newPersonnel.push({ | ||
...member, | ||
id: crypto.randomUUID(), | ||
project_id: newProject.id, | ||
created_at: creationDate, | ||
deleted: false, | ||
}) | ||
} | ||
}) | ||
await PersonnelModel.createMany(newPersonnel) | ||
} | ||
|
||
static async getProject(id: string) { | ||
//TODO: add all data to project from other tables (updates, personnel, milestones, etc) & return Project type, instead of ProjectAttributes | ||
const project = await ProjectModel.getProject(id) | ||
if (!project) { | ||
throw new Error(`Project not found: "${id}"`) | ||
|
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.
Are we validating this is an id?
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.
We are in the route handler, but I'll add a check in the model for xtra safu