Skip to content

Commit

Permalink
legacy document links
Browse files Browse the repository at this point in the history
Add support for legacy links to documents

closes #1508
  • Loading branch information
TangoYankee authored and TylerMatteo committed Apr 17, 2024
1 parent 7e87feb commit a744df0
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
43 changes: 43 additions & 0 deletions server/src/document/document.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ export class DocumentController {
}
}

@Get("/package/sites/*")
async streamPackageDocByUrl(@Param() sharepointRelativePath, @Res() res) {
const id = await this.documentService.getPackageDocumentId(
sharepointRelativePath[0]
);

const stream = await this.documentService.getPackageDocument(id);
stream.pipe(res);
}

@Get("/package/*")
async streamPackageDoc(@Param() sharepointRelativePath, @Res() res) {
const stream = await this.documentService.getPackageDocument(
Expand All @@ -102,6 +112,16 @@ export class DocumentController {
stream.pipe(res);
}

@Get("/artifact/sites/*")
async streamArtifactDocByUrl(@Param() sharepointRelativePath, @Res() res) {
const id = await this.documentService.getArtifactDocumentId(
sharepointRelativePath[0]
);

const stream = await this.documentService.getArtifactDocument(id);
stream.pipe(res);
}

@Get("/artifact/*")
async streamArtifactDoc(@Param() sharepointRelativePath, @Res() res) {
const stream = await this.documentService.getArtifactDocument(
Expand All @@ -111,6 +131,19 @@ export class DocumentController {
stream.pipe(res);
}

@Get("/projectaction/sites/*")
async streamProjectactionDocByUrl(
@Param() sharepointRelativePath,
@Res() res
) {
const id = await this.documentService.getProjectactionDocumentId(
sharepointRelativePath[0]
);

const stream = await this.documentService.getProjectactionDocument(id);
stream.pipe(res);
}

@Get("/projectaction/*")
async streamProjectactionDoc(@Param() sharepointRelativePath, @Res() res) {
const stream = await this.documentService.getProjectactionDocument(
Expand All @@ -120,6 +153,16 @@ export class DocumentController {
stream.pipe(res);
}

@Get("/disposition/sites/*")
async streamDispositionDocByUrl(@Param() sharepointRelativePath, @Res() res) {
const id = await this.documentService.getDispositionDocumentId(
sharepointRelativePath[0]
);

const stream = await this.documentService.getDispositionDocument(id);
stream.pipe(res);
}

@Get("/disposition/*")
async streamDispositionDoc(@Param() sharepointRelativePath, @Res() res) {
const stream = await this.documentService.getDispositionDocument(
Expand Down
32 changes: 32 additions & 0 deletions server/src/document/document.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ export class DocumentService {
private readonly crmService: CrmService,
private readonly sharepointService: SharepointService
) {}
public async getPackageDocumentId(relativeUrl: string) {
const driveId = this.sharepointService.driveIdMap.dcp_package;
return await this.sharepointService.getSharepointFileId(
driveId,
relativeUrl
);
}
// For info on the path param,
// see above documentation for the getRecordIdFromDocumentPath function
public async getPackageDocument(fileId) {
Expand Down Expand Up @@ -135,6 +142,14 @@ export class DocumentService {
}
}

public async getArtifactDocumentId(relativeUrl: string) {
const driveId = this.sharepointService.driveIdMap.dcp_artifact;
return await this.sharepointService.getSharepointFileId(
driveId,
relativeUrl
);
}

public async getArtifactDocument(fileId) {
const driveId = this.sharepointService.driveIdMap.dcp_artifact;
const {
Expand Down Expand Up @@ -172,6 +187,14 @@ export class DocumentService {
}
}

public async getProjectactionDocumentId(relativeUrl: string) {
const driveId = this.sharepointService.driveIdMap.dcp_projectaction;
return await this.sharepointService.getSharepointFileId(
driveId,
relativeUrl
);
}

public async getProjectactionDocument(fileId: string) {
const driveId = this.sharepointService.driveIdMap.dcp_projectaction;
const {
Expand Down Expand Up @@ -209,6 +232,15 @@ export class DocumentService {
}
}

public async getDispositionDocumentId(relativeUrl: string) {
const driveId = this.sharepointService.driveIdMap
.dcp_communityboarddisposition;
return await this.sharepointService.getSharepointFileId(
driveId,
relativeUrl
);
}

public async getDispositionDocument(fileId) {
const driveId = this.sharepointService.driveIdMap
.dcp_communityboarddisposition;
Expand Down
42 changes: 42 additions & 0 deletions server/src/sharepoint/sharepoint.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,46 @@ export class SharepointService {
const response = await fetch(url, options);
return await response.json();
}

async getSharepointFileId(driveId: string, relativeUrl: string) {
const filePath = relativeUrl.split("/");
if (filePath.length < 2)
throw new HttpException(
{
code: "DISPOSITION_ID_PATH",
title: "Disposition ID Path Error"
},
HttpStatus.BAD_REQUEST
);
const folderName = filePath[filePath.length - 2];
const fileName = filePath[filePath.length - 1];

const { accessToken } = await this.msalProvider.getGraphClientToken();
const url = `${
this.msalProvider.sharePointSiteUrl
}/drives/${driveId}/root:/${folderName}:/children?$filter=(name eq '${fileName}')&$select=id`;
const options = {
headers: {
method: "GET",
Authorization: `Bearer ${accessToken}`,
Accept: "application/json"
}
};

const response = await fetch(url, options);
const data = (await response.json()) as
| { value: Array<{ id: string }> }
| { message: string };
if ("value" in data && data.value.length > 0) {
return data.value[0].id;
} else {
throw new HttpException(
{
code: "DISPOSITION_ID_RESULT",
title: "Disposition ID Result Error"
},
HttpStatus.NOT_FOUND
);
}
}
}

0 comments on commit a744df0

Please sign in to comment.