From 99a7ccc8f34df8ce694ca58e685360024f9d64d3 Mon Sep 17 00:00:00 2001 From: horatio Date: Wed, 8 Jan 2025 10:43:30 -0500 Subject: [PATCH] cherrypick changes from ty/1254/upload-documents --- .github/workflows/production.yml | 2 + .github/workflows/staging.yml | 2 + client/app/components/projects/new.hbs | 24 ++++++---- client/app/components/projects/new.js | 5 +++ .../projects/projects-new-attachments.hbs | 2 +- server/src/projects/projects.module.ts | 8 +++- server/src/projects/projects.service.ts | 45 +++++++------------ 7 files changed, 47 insertions(+), 41 deletions(-) diff --git a/.github/workflows/production.yml b/.github/workflows/production.yml index 06c9f178..f47bed15 100644 --- a/.github/workflows/production.yml +++ b/.github/workflows/production.yml @@ -36,6 +36,8 @@ jobs: - uses: actions/checkout@v4 with: sparse-checkout: server + - name: 'Install Heroku CLI' + run: curl https://cli-assets.heroku.com/install.sh | sh - uses: akhileshns/heroku-deploy@v3.13.15 name: Deploy server to Heroku with: diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml index a36f397c..7a2c58ba 100644 --- a/.github/workflows/staging.yml +++ b/.github/workflows/staging.yml @@ -40,6 +40,8 @@ jobs: with: ref: 'main' sparse-checkout: server + - name: 'Install Heroku CLI' + run: curl https://cli-assets.heroku.com/install.sh | sh - uses: akhileshns/heroku-deploy@v3.13.15 name: Deploy server to Heroku with: diff --git a/client/app/components/projects/new.hbs b/client/app/components/projects/new.hbs index a4c4416e..d9f8bf87 100644 --- a/client/app/components/projects/new.hbs +++ b/client/app/components/projects/new.hbs @@ -47,17 +47,23 @@ -
Confirm New Project Submission
-

- Are you sure? -

-

- Before submitting, ensure that your answers are accurate and complete, and that necessary attachments have been uploaded. If NYC Planning does not receive enough accurate information to provide guidance, the Lead Planner will notify you and request that this form be resubmitted with necessary materials, corrections, or - clarifications. -

+ {{#if this.submissionError}} +

Error while creating project. Lorem Ipsum.....

+ {{else}} +

+ Are you sure? +

+

+ Before submitting, ensure that your answers are accurate and complete, and that necessary attachments have been + uploaded. If NYC Planning does not receive enough accurate information to provide guidance, the Lead Planner will + notify you and request that this form be resubmitted with necessary materials, corrections, or + clarifications. +

+ {{/if}}
diff --git a/client/app/components/projects/new.js b/client/app/components/projects/new.js index 9486e44c..ef264f66 100644 --- a/client/app/components/projects/new.js +++ b/client/app/components/projects/new.js @@ -1,5 +1,6 @@ import Component from '@glimmer/component'; import { action } from '@ember/object'; +import { tracked } from '@glimmer/tracking'; import { inject as service } from '@ember/service'; import SubmittableProjectsNewForm from '../../validations/submittable-projects-new-form'; import { optionset } from '../../helpers/optionset'; @@ -11,6 +12,8 @@ export default class ProjectsNewFormComponent extends Component { SubmittableProjectsNewForm, }; + @tracked submissionError = false; + requestCounter = 0; @service @@ -29,6 +32,7 @@ export default class ProjectsNewFormComponent extends Component { @action async submitProject() { + this.submissionError = false; const requestStartTime = Date.now(); this.requestCounter++; console.log(`LOGGER: [Total Requests Made in the client controller] ${this.requestCounter}`); @@ -134,6 +138,7 @@ export default class ProjectsNewFormComponent extends Component { this.router.transitionTo('projects'); } catch { + this.submissionError = true; /* eslint-disable-next-line no-console */ console.error('Error while creating project'); } diff --git a/client/app/components/projects/projects-new-attachments.hbs b/client/app/components/projects/projects-new-attachments.hbs index b0ed9444..f771f631 100644 --- a/client/app/components/projects/projects-new-attachments.hbs +++ b/client/app/components/projects/projects-new-attachments.hbs @@ -130,4 +130,4 @@ The size limit for each file is 50 MB. You can upload up to 1 GB of files.

- \ No newline at end of file + diff --git a/server/src/projects/projects.module.ts b/server/src/projects/projects.module.ts index 48b3b693..6614eaf9 100644 --- a/server/src/projects/projects.module.ts +++ b/server/src/projects/projects.module.ts @@ -10,7 +10,13 @@ import { ArtifactService } from '../artifacts/artifacts.service'; import { SharepointModule } from '../sharepoint/sharepoint.module'; @Module({ - imports: [CrmModule, SharepointModule, ConfigModule, ContactModule, AuthModule], + imports: [ + CrmModule, + SharepointModule, + ConfigModule, + ContactModule, + AuthModule, + ], providers: [ProjectsService, ArtifactService], exports: [ProjectsService], controllers: [ProjectsController, ProjectApplicantController], diff --git a/server/src/projects/projects.service.ts b/server/src/projects/projects.service.ts index fee58699..4b76845c 100644 --- a/server/src/projects/projects.service.ts +++ b/server/src/projects/projects.service.ts @@ -128,56 +128,41 @@ export class ProjectsService { // 'dcp_projects', // data, // ); - const crmResponse = await this.crmService.get( + const { records } = await this.crmService.get( 'dcp_projects', // 3e5 = created within 5 minutes - ` $filter= - dcp_projectname eq '${data.dcp_projectname}' + dcp_projectname eq '${encodeURIComponent(data.dcp_projectname)}' and createdon ge '${new Date(Date.now() - 3e5).toISOString()}' ` ) - const { records } = crmResponse; - console.debug('LOGGER: crm response', crmResponse); - try { - if (records.length > 0) { - console.log('Project already exists'); - throw new Error('Project already exists'); - } - } catch (e) { - - } + console.debug('LOGGER: crm records', records); + if (records.length > 0) throw new Error('Project already exists'); - const project = await this.crmService.create( - 'dcp_projects', - data, - ); + const project = await this.crmService.create('dcp_projects', data); // console.debug("LOGGER: (service) project", project); - const { dcp_projectid } = project; - - // const { dcp_artifactsid } = - // await this.artifactService.createProjectInitiationArtifacts( - // dcp_projectid, - // ); + const dcpProjectId = project['dcp_projectid']; + if (dcpProjectId === undefined) throw new Error('Failed to create project'); const artifact = - await this.artifactService.createProjectInitiationArtifacts( - dcp_projectid, - ); + await this.artifactService.createProjectInitiationArtifacts(dcpProjectId); + // console.debug('LOGGER: (service) artifact', artifact); - const { dcp_artifactsid } = artifact; + const dcpArtifactsId = artifact['dcp_artifactsid']; + if (dcpArtifactsId === undefined) throw new Error('Failed to create artifact for project'); + const requestEndTime = Date.now(); console.debug(`LOGGER: POST (service) request in the service to took ${requestEndTime - requestStartTime} ms`); requestCounter++; console.log(`LOGGER: [Total Requests Made in the service] ${requestCounter}`); return { - dcp_projectid, - dcp_artifactsid, + dcp_projectid: dcpProjectId, + dcp_artifactsid: dcpArtifactsId, }; } catch (e) { - console.debug('(service) error creating project', e); + console.error('(service) error creating project', e); throw new HttpException( 'Unable to create project', HttpStatus.INTERNAL_SERVER_ERROR,