2021-05-12 06:35:00 +00:00
|
|
|
import { database as db } from '../../common/database';
|
|
|
|
import { GrpcRequest, type as GrpcRequestType } from '../grpc-request';
|
2021-07-22 23:04:56 +00:00
|
|
|
import { Request, type as RequestType } from '../request';
|
2021-05-12 06:35:00 +00:00
|
|
|
import { Workspace } from '../workspace';
|
2020-12-17 11:38:21 +00:00
|
|
|
|
|
|
|
export const queryAllWorkspaceUrls = async (
|
2021-05-12 06:35:00 +00:00
|
|
|
workspace: Workspace | null,
|
|
|
|
reqType: typeof RequestType | typeof GrpcRequestType,
|
|
|
|
reqId = 'n/a',
|
2021-05-18 20:32:18 +00:00
|
|
|
): Promise<string[]> => {
|
2020-12-17 11:38:21 +00:00
|
|
|
const docs = await db.withDescendants(workspace, reqType);
|
|
|
|
const urls = docs
|
|
|
|
.filter(
|
2021-06-30 07:47:17 +00:00
|
|
|
(d: Request | GrpcRequest) =>
|
2020-12-17 11:38:21 +00:00
|
|
|
d.type === reqType &&
|
|
|
|
d._id !== reqId && // Not current request
|
|
|
|
(d.url || ''), // Only ones with non-empty URLs
|
|
|
|
)
|
|
|
|
.map((r: Request | GrpcRequest) => (r.url || '').trim());
|
|
|
|
return Array.from(new Set(urls));
|
|
|
|
};
|