Skip to content

Commit 87c7cf6

Browse files
committed
review endpoint
1 parent 5a00eaa commit 87c7cf6

File tree

6 files changed

+35
-12
lines changed

6 files changed

+35
-12
lines changed

src/api/core/ChangeRequestDB.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,12 @@ class ChangeRequestDB {
343343
return userDatabase.getVersionDiff(originalBranch, trackingBranch, undefined,options)
344344
}
345345

346+
checkUserReadAuthorization () {
347+
const tmpClient = this.connectWithCurrentUser()
348+
const query = TerminusClient.WOQL.limit(1).triple('v:a', 'v:b', 'v:c')
349+
return tmpClient.query(query)
350+
}
351+
346352
async addMessage (changeIdHash:string, message:string) {
347353
const changeId = `ChangeRequest/${changeIdHash}`
348354
const requestDoc = await this.client.getDocument({ id: changeId })
@@ -456,14 +462,15 @@ class ChangeRequestDB {
456462
}
457463
}
458464

459-
async getLastCommitsIndexed (limit = 1, status?:string) {
465+
async getLastCommitsIndexed (limit = 1, status?:string, branch?:string) {
460466
try {
461467
const WOQL = TerminusClient.WOQL
462468
const statusVar = status && this.availableStatus[status] ? `@schema:Indexing_Status/${status}` : 'v:indexing_status'
469+
const branchVar = branch ? WOQL.string(branch) : 'v:branch'
463470
const query = WOQL.limit(limit).order_by(['v:time', 'desc']).and(
464471
WOQL.triple('v:index', 'rdf:type', '@schema:Indexed_commit'),
465472
WOQL.triple('v:index', '@schema:change_request_commit_id', 'v:commit_id'),
466-
WOQL.triple('v:index', '@schema:searchable_branch_name', 'v:branch'),
473+
WOQL.triple('v:index', '@schema:searchable_branch_name', branchVar),
467474
WOQL.triple('v:index', '@schema:indexing_status', statusVar),
468475
WOQL.triple('v:index', '@schema:searchable_branch_commit_id', 'v:searchable_commit'),
469476
WOQL.triple('v:index', '@schema:indexed_at', 'v:time'),

src/api/core/GraphqlTableConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ class GraphqlTableConfig {
219219
const result = await client.query({ query })
220220
const schemaDoc = await woqlClient.getDocument({ graph_type: 'schema', as_list: true })
221221
const tableConfig = this.formatSchema(result, schemaDoc)
222-
this.logger.debug(JSON.stringify(tableConfig, null, 4))
222+
//this.logger.debug(JSON.stringify(tableConfig, null, 4))
223223
return tableConfig
224224
}
225225

src/api/core/IndexClient.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ export function assignCommit (logger:any, domain:any, sourceCommit:any, targetCo
3131
return axios.get(`${baseUrl}assign`, config)
3232
}
3333

34-
export function searchIndex (req:Request, apikey?:string) {
34+
export function searchIndex (req:Request, domain:string, commit:string, apikey?:string) {
3535
if(!apikey) throw new Error("Plase set a valid OpenAI api key")
3636
const headers = { VECTORLINK_EMBEDDING_API_KEY: apikey, 'Content-Type': 'text/plain' }
37-
const domain = req.query.domain
38-
const commit = req.query.commit
3937
const config = { headers, params: { commit: commit, domain: domain } }
4038
return axios.post(`${baseUrl}search`, req.body.search, config)
4139
}

src/api/paths/api/changes/{org}/{db}/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import ChangeRequestDB from "../../../../../core/ChangeRequestDB";
2727
const message = req.body.message || "create a new change request"
2828
const changeR = new ChangeRequestDB(req)
2929
const crId= await changeR.createChangeRequest(message)
30-
console.log(`About to create Change Request: ${JSON.stringify(req.body)}`);
30+
//console.log(`About to create Change Request: ${JSON.stringify(req.body)}`);
3131
res.status(201).send({message:"the change request as been created",...crId});
3232
}catch(err:any){
3333
console.log(err.message)

src/api/paths/api/indexes/{org}/{db}/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ import ChangeRequestDB from "../../../../../core/ChangeRequestDB";
55
export const GET: Operation = async(req:Request, res:Response) =>{
66
try{
77
const changeR = new ChangeRequestDB(req)
8+
// check if the user has read access
9+
await changeR.checkUserReadAuthorization()
810
const limitPar:string = typeof req.query.limit === "string" ? req.query.limit : '5'
911
const limit:number = parseInt(limitPar)
1012
const status = typeof req.query.status === "string" ? req.query.status : undefined
11-
const commits = await changeR.getLastCommitsIndexed(limit, status)
13+
const branch = typeof req.query.branch === "string" ? req.query.branch : undefined
14+
const commits = await changeR.getLastCommitsIndexed(limit, status, branch)
1215
res.status(200).json(commits)
1316
}catch(err:any){
1417
console.log(err.message)
@@ -46,7 +49,13 @@ import ChangeRequestDB from "../../../../../core/ChangeRequestDB";
4649
name: "status",
4750
required: false,
4851
type: "string"
49-
}
52+
},
53+
{
54+
in: "query",
55+
name: "branch",
56+
required: false,
57+
type: "string"
58+
},
5059
],
5160
responses: {
5261
200: {

src/api/paths/api/indexes/{org}/{db}/search/index.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import { Operation } from "express-openapi";
22
import { Request,Response, } from "express";
33
import * as IndexClient from '../../../../../../core/IndexClient'
4-
4+
import ChangeRequestDB from "../../../../../../core/ChangeRequestDB";
55

66
export const POST: Operation = async (req:Request, res:Response) =>{
77
try {
8+
const changeDB = new ChangeRequestDB(req)
9+
await changeDB.checkUserReadAuthorization()
810
const apiKey = process.env.OPENAI_KEY
9-
10-
const result = await IndexClient.searchIndex(req, apiKey)
11+
const commit = req.query.commit as string
12+
const domain = `${req.params.org}/${req.params.db}`
13+
const result = await IndexClient.searchIndex(req, domain, commit, apiKey)
1114
res.json(result.data)
1215
} catch (err:any) {
1316
//req.context.logger.error(err)
@@ -33,6 +36,12 @@ import * as IndexClient from '../../../../../../core/IndexClient'
3336
required: true,
3437
type: "string"
3538
},
39+
{
40+
in: "query",
41+
name: "commit",
42+
required: true,
43+
type: "string"
44+
},
3645
{
3746
in: "body",
3847
name: "change request",

0 commit comments

Comments
 (0)