Skip to content
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

19/graph api #1503

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions client/config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

const { MIRAGE_SCENARIO } = process.env;
const NYCID_CLIENT_ID = process.env.NYCID_CLIENT_ID || 'lup-portal-local';
const NYC_ID_HOST = process.env.NYC_ID_HOST || 'https://accounts-nonprd.nyc.gov/account';
const NYC_ID_HOST =
process.env.NYC_ID_HOST || 'https://accounts-nonprd.nyc.gov/account';

module.exports = function(environment) {
module.exports = function (environment) {
const ENV = {
modulePrefix: 'labs-zap-search',
environment,
Expand Down Expand Up @@ -77,7 +78,8 @@ module.exports = function(environment) {
debug: environment === 'debug-ga',
trace: environment === 'debug-ga',
// Ensure development env hits aren't sent to GA
sendHitTask: (environment !== 'development' && environment !== 'devlocal'),
sendHitTask:
environment !== 'development' && environment !== 'devlocal',
},
},
{
Expand Down Expand Up @@ -147,7 +149,8 @@ module.exports = function(environment) {
enabled: false,
};

ENV['mapbox-gl'].map.style = 'https://labs-layers-api.herokuapp.com/v1/base/style.json';
ENV['mapbox-gl'].map.style =
'https://labs-layers-api.herokuapp.com/v1/base/style.json';
}

if (environment !== 'production') {
Expand Down
25 changes: 17 additions & 8 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"prepare": "cd .. && husky install .husky"
},
"dependencies": {
"@azure/msal-node": "^2.6.5",
"@nestjs/common": "^7.6.15",
"@nestjs/core": "^7.6.15",
"@nestjs/platform-express": "^7.6.15",
Expand Down Expand Up @@ -84,28 +85,36 @@
"devDependencies": {
"@nestjs/cli": "^7.6.0",
"@nestjs/schematics": "^7.3.1",
"@types/compression": "^1.7.5",
"@types/express": "^4.17.1",
"@types/jest": "^26.0.22",
"@types/jsonwebtoken": "^8.3.4",
"@types/inflected": "^2.1.3",
"@types/jest": "^29.5.12",
"@types/jsonwebtoken": "^8.5.1",
"@types/node": "11.13.4",
"@types/supertest": "2.0.7",
"jest": "^26.6.3",
"@types/request": "^2.48.12",
"@types/superagent-proxy": "3.0.4",
"@types/supertest": "^6.0.2",
"@types/underscore": "^1.11.15",
"jest": "^29.7.0",
"lint-staged": ">=10",
"prettier": "1.17.0",
"supertest": "5.0.0-0",
"ts-jest": "^26.5.4",
"ts-node": "8.1.0",
"supertest": "^6.3.4",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"tsc-watch": "2.2.1",
"tsconfig-paths": "3.8.0",
"tslint": "5.16.0",
"typescript": "^3.7.2"
"typescript": "^4.2.3"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"moduleNameMapper": {
"src/(.*)": "<rootDir>/$1"
},
"rootDir": "src",
"testRegex": ".spec.ts$",
"transform": {
Expand Down
44 changes: 24 additions & 20 deletions server/src/_utils/adal.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import * as ADALNode from 'adal-node';
import * as ADALNode from "adal-node";

export const ADAL = {
ADAL_CONFIG: {
CRMUrl: '',
webAPIurl: '',
clientId: '',
clientSecret: '',
tenantId: '',
authorityHostUrl: '',
tokenPath: '',
CRMUrl: "",
webAPIurl: "",
clientId: "",
clientSecret: "",
tenantId: "",
authorityHostUrl: "",
tokenPath: ""
},

token: null,
expirationDate: null,
acquireToken() {
return new Promise((resolve, reject) => {
if (this.expirationDate) {
const tokenLimit = new Date(this.expirationDate.getTime() - (15*60*1000));
const tokenLimit = new Date(
this.expirationDate.getTime() - 15 * 60 * 1000
);
const now = new Date();

if (now <= tokenLimit){
if (now <= tokenLimit) {
resolve(this.token);

return;
Expand All @@ -33,28 +35,30 @@ export const ADAL = {
tokenPath,
clientId,
clientSecret,
CRMUrl,
CRMUrl
} = this.ADAL_CONFIG;
const context = new AuthenticationContext(`${authorityHostUrl}/${tenantId}${tokenPath}`);
const context = new AuthenticationContext(
`${authorityHostUrl}/${tenantId}${tokenPath}`
);

context.acquireTokenWithClientCredentials(CRMUrl, clientId, clientSecret,
(err, tokenResponse:any ) => {
context.acquireTokenWithClientCredentials(
CRMUrl,
clientId,
clientSecret,
(err, tokenResponse: any) => {
if (err) {
console.log(`well that didn't work: ${err.stack}`);
reject(err);
}

const {
accessToken,
expiresOn,
} = tokenResponse;
const { accessToken, expiresOn } = tokenResponse;

this.token = accessToken;
this.expirationDate = expiresOn;

resolve(accessToken);
}
);
})
},
});
}
};
22 changes: 14 additions & 8 deletions server/src/_utils/crm-web-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ export const CRMWebAPI = {
const encoding = response.headers["content-encoding"];
if (
error ||
(response.status != 200 &&
response.status != 204 &&
response.status != 1223)
(response.statusCode != 200 &&
response.statusCode != 204 &&
response.statusCode != 1223)
) {
const parseError = jsonText => {
// Bug: sometimes CRM returns 'object reference' error
Expand All @@ -258,7 +258,7 @@ export const CRMWebAPI = {
} else {
parseError(body);
}
} else if (response.status === 200) {
} else if (response.statusCode === 200) {
const parseResponse = jsonText => {
const json_string = jsonText.toString("utf-8");
var result = JSON.parse(json_string, this.dateReviver);
Expand All @@ -272,9 +272,12 @@ export const CRMWebAPI = {
} else {
parseResponse(body);
}
} else if (response.status === 204 || response.status === 1223) {
const uri = response.headers.get("OData-EntityId");
if (uri) {
} else if (
response.statusCode === 204 ||
response.statusCode === 1223
) {
const uri = response.headers["OData-EntityId"];
if (uri && typeof uri === "string") {
// create request - server sends new id
const regExp = /\(([^)]+)\)/;
const matches = regExp.exec(uri);
Expand Down Expand Up @@ -312,7 +315,10 @@ export const CRMWebAPI = {
return new Promise<void>((resolve, reject) => {
request.patch(options, (error, response, body) => {
const encoding = response.headers["content-encoding"];
if (error || (response.status != 204 && response.status != 1223)) {
if (
error ||
(response.statusCode != 204 && response.statusCode != 1223)
) {
const parseError = jsonText => {
const json_string = jsonText.toString("utf-8");
let result = {};
Expand Down
8 changes: 4 additions & 4 deletions server/src/_utils/get-query-file.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as path from 'path';
import * as pgp from 'pg-promise';
import * as rootPath from 'app-root-path';
import * as path from "path";
import * as pgp from "pg-promise";
import * as rootPath from "app-root-path";

// imports a pgp SQL Queryfile
export function getQueryFile(file) {
const fullPath = path.join(`${rootPath}/queries`, file);
return new pgp.QueryFile(fullPath, { minify: true });
};
}
20 changes: 10 additions & 10 deletions server/src/app.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AuthService } from './auth/auth.service';
import { ContactService } from './contact/contact.service';
import { AppController } from './app.controller';
import { Test, TestingModule } from "@nestjs/testing";
import { AuthService } from "./auth/auth.service";
import { ContactService } from "./contact/contact.service";
import { AppController } from "./app.controller";

describe('App Controller', () => {
describe("App Controller", () => {
let controller: AppController;

beforeEach(async () => {
Expand All @@ -12,21 +12,21 @@ describe('App Controller', () => {
{
provide: AuthService,
// how you provide the injection token in a test instance
useValue: new (class Mock { }),
useValue: new (class Mock {})()
},
{
provide: ContactService,
// how you provide the injection token in a test instance
useValue: new (class Mock { }),
},
useValue: new (class Mock {})()
}
],
controllers: [AppController],
controllers: [AppController]
}).compile();

controller = module.get<AppController>(AppController);
});

it('should be defined', () => {
it("should be defined", () => {
expect(controller).toBeDefined();
});
});
58 changes: 27 additions & 31 deletions server/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Module, NestModule, MiddlewareConsumer } from '@nestjs/common';
import * as bodyParser from 'body-parser';
import * as cookieparser from 'cookie-parser';
import * as compression from 'compression';
import { AuthMiddleware } from './auth.middleware';
import { ConfigModule } from './config/config.module';
import { ProjectModule } from './project/project.module';
import { AppController } from './app.controller';
import { ContactModule } from './contact/contact.module';
import { AuthModule } from './auth/auth.module';
import { DispositionModule } from './disposition/disposition.module';
import { AssignmentModule } from './assignment/assignment.module';
import { DocumentModule } from './document/document.module';
import { CrmModule } from './crm/crm.module';
import { ZoningResolutionsModule } from './zoning-resolutions/zoning-resolutions.module';
import { Module, NestModule, MiddlewareConsumer } from "@nestjs/common";
import bodyParser from "body-parser";
import cookieparser from "cookie-parser";
import compression from "compression";
import { AuthMiddleware } from "./auth.middleware";
import { ConfigModule } from "./config/config.module";
import { ProjectModule } from "./project/project.module";
import { AppController } from "./app.controller";
import { ContactModule } from "./contact/contact.module";
import { AuthModule } from "./auth/auth.module";
import { DispositionModule } from "./disposition/disposition.module";
import { AssignmentModule } from "./assignment/assignment.module";
import { DocumentModule } from "./document/document.module";
import { CrmModule } from "./crm/crm.module";
import { ZoningResolutionsModule } from "./zoning-resolutions/zoning-resolutions.module";

@Module({
imports: [
Expand All @@ -24,28 +24,24 @@ import { ZoningResolutionsModule } from './zoning-resolutions/zoning-resolutions
DispositionModule,
AssignmentModule,
DocumentModule,
ZoningResolutionsModule,
],
controllers: [AppController],
ZoningResolutionsModule
],
controllers: [AppController]
})
export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer
.apply(cookieparser())
.forRoutes('*');
consumer.apply(cookieparser()).forRoutes("*");

consumer
.apply(AuthMiddleware)
.forRoutes('*');
consumer.apply(AuthMiddleware).forRoutes("*");

consumer
.apply(bodyParser.json({
type: 'application/vnd.api+json'
}))
.forRoutes('*');
.apply(
bodyParser.json({
type: "application/vnd.api+json"
})
)
.forRoutes("*");

consumer
.apply(compression())
.forRoutes('*');
consumer.apply(compression()).forRoutes("*");
}
}
20 changes: 7 additions & 13 deletions server/src/artifact/artifact.module.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import { Module } from '@nestjs/common';
import { SharepointModule } from '../sharepoint/sharepoint.module';
import { ArtifactService } from './artifact.service'
import { Module } from "@nestjs/common";
import { SharepointModule } from "../sharepoint/sharepoint.module";
import { ArtifactService } from "./artifact.service";

@Module({
imports: [
SharepointModule,
],
providers: [
ArtifactService,
],
exports: [
ArtifactService,
],
controllers: [],
imports: [SharepointModule],
providers: [ArtifactService],
exports: [ArtifactService],
controllers: []
})
export class ArtifactModule {}
12 changes: 7 additions & 5 deletions server/src/artifact/artifact.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ export class ArtifactService {
async getArtifactSharepointDocuments(relativeUrl, dcp_name) {
if (relativeUrl) {
try {
const folderPath = relativeUrl.split("/");
const folderName = folderPath[folderPath.length - 1];
const documents = await this.sharepointService.getSharepointFolderFiles(
`dcp_artifacts/${relativeUrl}`,
"?$expand=Files,Folders,Folders/Files,Folders/Folders/Files,Folders/Folders/Folders/Files"
this.sharepointService.driveIdMap.dcp_artifact,
folderName
);

if (documents) {
return documents.map(document => ({
name: document["Name"],
timeCreated: document["TimeCreated"],
serverRelativeUrl: document["ServerRelativeUrl"]
name: document.name,
timeCreated: document.createdDateTime,
serverRelativeUrl: `/${document.id}`
}));
}

Expand Down
Loading
Loading