Skip to content

Commit

Permalink
using letter uuid for letter filetype
Browse files Browse the repository at this point in the history
  • Loading branch information
horatiorosa committed Nov 26, 2024
1 parent b79bead commit 11457bd
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 63 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
deploy-server:
name: 🚀 Deploy server
needs: test-client
environment:
environment:
name: production
url: https://applicants-api.nycplanningdigital.com
runs-on: ubuntu-latest
Expand All @@ -46,6 +46,7 @@ jobs:
appdir: server
env:
HD_FEATURE_FLAG_SELF_SERVICE: ${{ vars.FEATURE_FLAG_SELF_SERVICE }}
HD_LETTER_FILETYPE_UUID: ${{ vars.LETTER_FILETYPE_UUID }}
HD_ADO_PRINCIPAL: ${{ secrets.ADO_PRINCIPAL }}
HD_AUTHORITY_HOST_URL: ${{ secrets.AUTHORITY_HOST_URL }}
HD_CITYPAY_AGENCYID: ${{ secrets.CITYPAY_AGENCYID }}
Expand Down Expand Up @@ -107,7 +108,7 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 12.x
- name: Install application dependencies
- name: Install application dependencies
working-directory: client
run: yarn install --immutable --immutable-cache --check-cache
- name: Build client
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
appdir: server
env:
HD_FEATURE_FLAG_SELF_SERVICE: ${{ vars.FEATURE_FLAG_SELF_SERVICE }}
HD_LETTER_FILETYPE_UUID: ${{ vars.LETTER_FILETYPE_UUID }}
HD_ADO_PRINCIPAL: ${{ secrets.ADO_PRINCIPAL }}
HD_AUTHORITY_HOST_URL: ${{ secrets.AUTHORITY_HOST_URL }}
HD_CITYPAY_AGENCYID: ${{ secrets.CITYPAY_AGENCYID }}
Expand Down Expand Up @@ -102,7 +103,7 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 12.x
- name: Install application dependencies
- name: Install application dependencies
working-directory: client
run: yarn install --immutable --immutable-cache --check-cache
- name: Build client
Expand All @@ -119,4 +120,3 @@ jobs:
--site ${{secrets.NETLIFY_SITE_ID}} \
--auth ${{secrets.NETLIFY_AUTH_TOKEN}} \
--message "${{ github.event.head_commit.message }}"
3 changes: 2 additions & 1 deletion .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
appdir: server
env:
HD_FEATURE_FLAG_SELF_SERVICE: ${{ vars.FEATURE_FLAG_SELF_SERVICE }}
HD_LETTER_FILETYPE_UUID: ${{ vars.LETTER_FILETYPE_UUID }}
HD_ADO_PRINCIPAL: ${{ secrets.ADO_PRINCIPAL }}
HD_AUTHORITY_HOST_URL: ${{ secrets.AUTHORITY_HOST_URL }}
HD_CLIENT_ID: ${{ secrets.CLIENT_ID }}
Expand Down Expand Up @@ -94,7 +95,7 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 12.x
- name: Install application dependencies
- name: Install application dependencies
working-directory: client
run: yarn install
- name: Build client
Expand Down
2 changes: 1 addition & 1 deletion client/app/components/packages/attachments.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class PackagesAttachmentsComponent extends Component {
@action
trackFileForUpload() {
this.fileManager.trackFileForUpload();
console.log('attachments js uploaded files', this.fileManager);

this.args.package.documents = [...this.args.package.documents, ...this.fileManager.filesToUpload.files];
}

Expand Down
7 changes: 5 additions & 2 deletions client/app/components/projects/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,18 @@ export default class ProjectsNewFormComponent extends Component {
dcpApplicanttype: this.args.package.applicantType.code,
dcpProjectbrief: this.args.package.projectBrief,
_dcpApplicantadministratorCustomerValue:
verifiedPrimaryContact.id,
verifiedPrimaryContact.id,
_dcpApplicantCustomerValue: verifiedApplicant.id,
},
},
}),
});
const { data: project } = await response.json();
console.log(`project in new.js conponent`, project);

this.args.package.saveAttachedFiles(project.attributes['dcp-artifactsid']);

this.router.transitionTo('project', project.id);

} catch {

Check failure on line 111 in client/app/components/projects/new.js

View workflow job for this annotation

GitHub Actions / 🧪 Test client code

Block must not be padded by blank lines

Check failure on line 111 in client/app/components/projects/new.js

View workflow job for this annotation

GitHub Actions / 🧪 Test client code

Block must not be padded by blank lines
/* eslint-disable-next-line no-console */
console.error('Error while creating project');
Expand Down
1 change: 0 additions & 1 deletion client/app/components/projects/projects-new-attachments.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export default class ProjectsNewAttachmentsComponent extends Component {
@action
trackFileForUpload() {
/* eslint-disable-next-line no-console */
console.log('projects new attachments js uploaded files', this.fileManager);
this.fileManager.trackFileForUpload();
this.args.package.documents = [
...this.args.package.documents,
Expand Down
1 change: 0 additions & 1 deletion client/app/models/artifact.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export default class ArtifactModel extends Model {
this.fileUploadErrors = null;

try {
console.log(`fileManager in artifact js`, this.fileManager);
await this.fileManager.save();
} catch (e) {
console.log('Error saving files: ', e);
Expand Down
30 changes: 26 additions & 4 deletions client/app/models/project-new.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,24 @@ export default class ProjectNew extends Model {
if (this.fileManager) {
this.fileManager.existingFiles = this.documents;
} else {
const fileQueue = this.fileQueue.create(
`artifact${this.id}`,
);
const fileQueue = this.fileQueue.create(`artifact${this.id}`);

this.fileManager = new FileManager(
this.id,
'artifact',
this.documents,
[],
fileQueue,
this.session,
this.session

Check failure on line 19 in client/app/models/project-new.js

View workflow job for this annotation

GitHub Actions / 🧪 Test client code

Missing trailing comma

Check failure on line 19 in client/app/models/project-new.js

View workflow job for this annotation

GitHub Actions / 🧪 Test client code

Missing trailing comma
);
}
}

// Since file upload doesn't perform requests through
// an Ember Model save() process, it doesn't automatically
// hydrate the package.adapterError property. When an error occurs
// during upload we have to manually hydrate a custom error property
// to trigger the error box displayed to the user.
@tracked
fileUploadErrors = null;

Expand Down Expand Up @@ -99,4 +102,23 @@ export default class ProjectNew extends Model {
defaultValue: () => [],
})
documents;

async saveAttachedFiles(instanceId) {
try {
await this.fileManager.save(instanceId);
} catch (e) {
console.log('Error saving files: ', e); // eslint-disable-line no-console

// See comment on the tracked fileUploadError property
// definition above.
this.fileUploadErrors = [
{
code: 'UPLOAD_DOC_FAILED',
title: 'Failed to upload documents',
detail:
'An error occured while uploading your documents. Please refresh and retry.',
},
];
}
}
}
63 changes: 37 additions & 26 deletions client/app/services/file-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export default class FileManager {
filesToUpload, // EmberFileUpload Queue Object
session,
) {
console.assert(entityType === 'package' || entityType === 'artifact', "entityType must be 'package' or 'artifact'");
console.assert(
entityType === 'package' || entityType === 'artifact',
"entityType must be 'package' or 'artifact'"

Check failure on line 17 in client/app/services/file-manager.js

View workflow job for this annotation

GitHub Actions / 🧪 Test client code

Missing trailing comma

Check failure on line 17 in client/app/services/file-manager.js

View workflow job for this annotation

GitHub Actions / 🧪 Test client code

Missing trailing comma
);

this.recordId = recordId;
this.entityType = entityType;
Expand Down Expand Up @@ -61,18 +64,23 @@ export default class FileManager {
this.numFilesToUpload -= 1;
}

async uploadFiles() {
async uploadFiles(instanceId = this.recordId) {
for (let i = 0; i < this.filesToUpload.files.length; i += 1) {
await this.filesToUpload.files[i].upload(`${ENV.host}/documents/${this.entityType}`, { // eslint-disable-line
fileKey: 'file',
headers: {
Authorization: `Bearer ${this.session.data.authenticated.access_token}`,
},
data: {
instanceId: this.recordId,
entityName: this.entityType === 'artifact' ? 'dcp_artifacts' : 'dcp_package',
},
});
await this.filesToUpload.files[i].upload(

Check failure on line 69 in client/app/services/file-manager.js

View workflow job for this annotation

GitHub Actions / 🧪 Test client code

Unexpected `await` inside a loop

Check failure on line 69 in client/app/services/file-manager.js

View workflow job for this annotation

GitHub Actions / 🧪 Test client code

Unexpected `await` inside a loop
`${ENV.host}/documents/${this.entityType}`,
{
// eslint-disable-line
fileKey: 'file',
headers: {
Authorization: `Bearer ${this.session.data.authenticated.access_token}`,
},
data: {
instanceId,
entityName:
this.entityType === 'artifact' ? 'dcp_artifacts' : 'dcp_package',
},
}

Check failure on line 82 in client/app/services/file-manager.js

View workflow job for this annotation

GitHub Actions / 🧪 Test client code

Missing trailing comma

Check failure on line 82 in client/app/services/file-manager.js

View workflow job for this annotation

GitHub Actions / 🧪 Test client code

Missing trailing comma
);
}
}

Expand All @@ -82,23 +90,26 @@ export default class FileManager {
// TODO: If this is not possible, rework this to be a
// POST request to a differently named endpoint, like
// deleteDocument
return Promise.all(this.filesToDelete.map((file) => fetch(
`${ENV.host}/documents?serverRelativeUrl=${file.serverRelativeUrl}`, {
method: 'DELETE',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.session.data.authenticated.access_token}`,
},
},
)));
return Promise.all(
this.filesToDelete.map((file) =>
fetch(
`${ENV.host}/documents?serverRelativeUrl=${file.serverRelativeUrl}`,
{
method: 'DELETE',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.session.data.authenticated.access_token}`,
},
}

Check failure on line 104 in client/app/services/file-manager.js

View workflow job for this annotation

GitHub Actions / 🧪 Test client code

Missing trailing comma

Check failure on line 104 in client/app/services/file-manager.js

View workflow job for this annotation

GitHub Actions / 🧪 Test client code

Missing trailing comma
)

Check failure on line 105 in client/app/services/file-manager.js

View workflow job for this annotation

GitHub Actions / 🧪 Test client code

Missing trailing comma

Check failure on line 105 in client/app/services/file-manager.js

View workflow job for this annotation

GitHub Actions / 🧪 Test client code

Missing trailing comma
)

Check failure on line 106 in client/app/services/file-manager.js

View workflow job for this annotation

GitHub Actions / 🧪 Test client code

Unexpected newline before '('

Check failure on line 106 in client/app/services/file-manager.js

View workflow job for this annotation

GitHub Actions / 🧪 Test client code

Missing trailing comma

Check failure on line 106 in client/app/services/file-manager.js

View workflow job for this annotation

GitHub Actions / 🧪 Test client code

Unexpected newline before ')'

Check failure on line 106 in client/app/services/file-manager.js

View workflow job for this annotation

GitHub Actions / 🧪 Test client code

Missing trailing comma
);
}

async save() {
async save(instanceId) {
// See TODO at top of this file.
console.log(`Saving uploads: ${ENV.host}/documents/${this.entityType}`);

await this.uploadFiles();
await this.uploadFiles(instanceId);

await this.deleteFiles();

Expand Down
9 changes: 4 additions & 5 deletions server/src/artifacts/artifacts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import { ConfigService } from '../config/config.service';
@Injectable()
export class ArtifactService {
rerFiletypeUuid = '';
letterFiletypeUuid= '';

constructor(
private readonly crmService: CrmService,
private readonly sharepointService: SharepointService,
private readonly config: ConfigService,
) {
this.rerFiletypeUuid = this.config.get('RER_FILETYPE_UUID');
this.letterFiletypeUuid = this.config.get('LETTER_FILETYPE_UUID');
}

public async createEquityReport(projectId: string) {
Expand Down Expand Up @@ -47,7 +49,6 @@ export class ArtifactService {

public async createProjectInitiationArtifacts(projectId: string) {
let newArtifact = null;
console.log(`project id: ${projectId}`);

try {
newArtifact = this.crmService.create('dcp_artifactses', {
Expand All @@ -56,13 +57,11 @@ export class ArtifactService {
dcp_filecreator: 717170000, // Applicant
dcp_filecategory: 717170006, // Other
dcp_visibility: 717170002, // Applicant Only
'[email protected]': `/dcp_filetypes(${'letter'})`,
'[email protected]': `/dcp_filetypes(${this.letterFiletypeUuid})`,
...(projectId
? { '[email protected]': `/dcp_projects(${projectId})` }
: {}),
});
console.debug('new artifact in artifact service', newArtifact);

});
} catch (e) {
throw new HttpException(
{
Expand Down
20 changes: 2 additions & 18 deletions server/src/projects/projects.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { PROJECTAPPLICANT_ATTRS } from './project-applicants/project-applicants.
import { TEAMMEMBER_ATTRS } from './team-members/team-members.attrs';
import { CONTACT_ATTRS } from '../contact/contacts.attrs';
import { INVOICE_ATTRS } from '../invoices/invoices.attrs';
import { ArtifactService } from '../artifacts/artifacts.service';

@UseInterceptors(
new JsonApiSerializeInterceptor('projects', {
Expand All @@ -39,6 +38,7 @@ import { ArtifactService } from '../artifacts/artifacts.service';
'team-members',
'contacts',
'milestones',
'dcp_artifactsid',
],
packages: {
ref: 'dcp_packageid',
Expand Down Expand Up @@ -89,7 +89,6 @@ export class ProjectsController {
private readonly contactService: ContactService,
private readonly config: ConfigService,
private readonly crmService: CrmService,
private readonly artifactService: ArtifactService,
) {
this.CRM_IMPOSTER_ID = this.config.get('CRM_IMPOSTER_ID');
}
Expand Down Expand Up @@ -151,22 +150,7 @@ export class ProjectsController {
);
}

let firstArtifactWithDocuments = {};
const newProject = await this.projectsService.create(allowedAttrs);
console.log(
`project id in projects controller: ${newProject.dcp_projectid}`,
);
try {
firstArtifactWithDocuments =
await this.artifactService.createProjectInitiationArtifacts(
newProject.dcp_projectid,
);
console.log('** create Project Artifacts', firstArtifactWithDocuments);
} catch (e) {
console.log('firstArtifactWithDocuments error in projects controller', e);
}

return newProject;
return await this.projectsService.create(allowedAttrs);
}

@Get('/:id')
Expand Down
8 changes: 8 additions & 0 deletions server/src/projects/projects.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { NycidService } from '../contact/nycid/nycid.service';
import { CrmService } from '../crm/crm.service';
import { overwriteCodesWithLabels } from '../_utils/overwrite-codes-with-labels';
import { MILESTONE_ATTRS, MILESTONE_NON_DATE_ATTRS } from './projects.attrs';
import { ArtifactService } from '../artifacts/artifacts.service';

const APPLICANT_ACTIVE_STATUS_CODE = 1;
const PROJECT_ACTIVE_STATE_CODE = 0;
Expand Down Expand Up @@ -52,6 +53,7 @@ export class ProjectsService {
constructor(
private readonly crmService: CrmService,
private readonly nycidService: NycidService,
private readonly artifactService: ArtifactService,
) {}

public async findManyByContactId(contactId: string) {
Expand Down Expand Up @@ -122,8 +124,14 @@ export class ProjectsService {
'dcp_projects',
data,
);
const { dcp_artifactsid } =
await this.artifactService.createProjectInitiationArtifacts(
dcp_projectid,
);

return {
dcp_projectid,
dcp_artifactsid,
};
} catch (e) {
console.debug('error creating project', e);
Expand Down

0 comments on commit 11457bd

Please sign in to comment.