Skip to content

Commit 5a00eaa

Browse files
committed
review api
1 parent 3346a3f commit 5a00eaa

File tree

9 files changed

+9212
-4014
lines changed

9 files changed

+9212
-4014
lines changed

package-lock.json

Lines changed: 9053 additions & 3989 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"license": "ISC",
2020
"dependencies": {
2121
"@apollo/client": "^3.7.16",
22+
"@terminusdb/terminusdb-client": "^10.0.30",
2223
"@types/swagger-ui-express": "^4.1.3",
2324
"apollo-cache-inmemory": "^1.6.6",
2425
"apollo-client": "^2.6.10",

src/api/api-doc.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,14 @@
194194
}
195195
}
196196
},
197+
"ChangeRequestActivationStatus":{
198+
"type":"object",
199+
"properties":{
200+
"isActive":{
201+
"type":"boolean"
202+
}
203+
}
204+
},
197205
"CheckIndexedCommitTask":{
198206
"type":"object",
199207
"properties":{

src/api/core/ChangeRequestDB.ts

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

346+
async addMessage (changeIdHash:string, message:string) {
347+
const changeId = `ChangeRequest/${changeIdHash}`
348+
const requestDoc = await this.client.getDocument({ id: changeId })
349+
const updateMessage = message || 'No new message'
350+
const messageObj = { author: this.user || '', '@type': 'Message', text: updateMessage, timestamp: Date.now() }
351+
requestDoc.messages.push(messageObj)
352+
await this.updateDocumentFixSchema(requestDoc, updateMessage)
353+
return requestDoc
354+
}
355+
346356
//apikey method
347357

348358
async createIndexInfoDoc(userDatabase:WOQLClient, requestDoc:typeDef.ChangeReqDoc,lastCommitCRBRanch:string,apiKey:string){

src/api/core/GraphqlTableConfig.ts

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,14 @@ class GraphqlTableConfig {
186186
// every dataproduct has the related change_request database
187187
}
188188

189-
async getSchema (organization:string, dbname:string, branchid:string) {
189+
async getSchema (organization:string, dbname:string, type:string, typeid:string) {
190190
const woqlClient = new TerminusClient.WOQLClient(endpoint, { user: this.user, key: this.password, organization:organization, db: dbname })
191191
const userPassEnc = btoa(`${this.user}:${this.password}`)
192-
woqlClient.checkout(branchid)
192+
if(type==="branch"){
193+
woqlClient.checkout(typeid)
194+
}else{
195+
woqlClient.ref(typeid)
196+
}
193197
const terminusdbURL = woqlClient.connectionConfig.branchBase('graphql')
194198

195199
const httpLink = new HttpLink({ uri: terminusdbURL });
@@ -238,19 +242,27 @@ class GraphqlTableConfig {
238242
}
239243

240244
advSearchFilterFormatter (typesObj:any, fieldKey:string, fieldTypeValue:AdvancedKeyType, isList:boolean) {
241-
// const advancedSearchObj = {}
242-
let advField:AdvancedSearchField = advancedSearchMatchType[fieldTypeValue]
243-
if (advField !== undefined) {
244-
advField = JSON.parse(JSON.stringify(advField))
245-
advField.label = fieldKey
246-
} else if (typesObj[fieldTypeValue] && typesObj[fieldTypeValue].type === 'ENUM') {
247-
advField = JSON.parse(JSON.stringify(advancedSearchMatchType.ENUM))
248-
advField.label = fieldKey
249-
advField.fieldSettings = {listValues : typesObj[fieldTypeValue].values}
245+
try{
246+
if(fieldKey==="homeworld"){
247+
console.log("stop")
248+
249+
}
250+
let advField:AdvancedSearchField = advancedSearchMatchType[fieldTypeValue] || {}
251+
if (advField !== undefined) {
252+
advField = JSON.parse(JSON.stringify(advField))
253+
advField.label = fieldKey
254+
} else if (typesObj[fieldTypeValue] && typesObj[fieldTypeValue].type === 'ENUM') {
255+
advField = JSON.parse(JSON.stringify(advancedSearchMatchType.ENUM))
256+
advField.label = fieldKey
257+
advField.fieldSettings = {listValues : typesObj[fieldTypeValue].values}
258+
}
259+
if (isList)advField.mode = 'ARRAY'
260+
advField.typevalue = fieldTypeValue
261+
return advField
262+
}catch(err:any){
263+
console.log("advSearchFilterFormatter",fieldKey,fieldTypeValue)
264+
throw err
250265
}
251-
if (isList)advField.mode = 'ARRAY'
252-
advField.typevalue = fieldTypeValue
253-
return advField
254266
}
255267

256268

@@ -313,7 +325,7 @@ class GraphqlTableConfig {
313325
typesObjKeys.forEach(key => {
314326
const itemObj = typesObj[key]
315327
if (itemObj && itemObj.type === 'OBJECT') {
316-
const fieldsKeys:string[] = itemObj.order_by || Object.keys(itemObj.fields || {})
328+
const fieldsKeys:string[] = itemObj.order_by || Object.keys(itemObj.fields || [])
317329

318330
const fieldKeysArr:FieldKeysItem[] = [{
319331
Header: 'ID',
@@ -355,7 +367,8 @@ class GraphqlTableConfig {
355367
accessor: fieldKey,
356368
filter: { type: 'list', options: { dataprovider: fieldTypeValueObj.values, ...isList } }
357369
})
358-
} else {
370+
}
371+
}else {
359372
const filter = this.getFilterType(fieldTypeValue)
360373
const columnObj:FieldKeysItem= {
361374
Header: fieldKey.toUpperCase(),
@@ -368,17 +381,14 @@ class GraphqlTableConfig {
368381
columnObj.disableSortBy = true
369382
}
370383
fieldKeysArr.push(columnObj)
371-
}
372-
}
384+
}
373385
}
374386
})// foreach
375387
tablesColumnsConfig[key] = fieldKeysArr
376388
//}
377389
}
378390
})
379391

380-
381-
382392
typesObjKeys.forEach(key => {
383393
const itemObj = typesObj[key]
384394
// const fieldsArr = []
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { Operation } from "express-openapi";
2+
import { Request,Response, } from "express";
3+
4+
export const GET: Operation = async(req:Request, res:Response) =>{
5+
try{
6+
const apiKey = process.env.USE_CHANGE_REQUEST && process.env.USE_CHANGE_REQUEST === "true" ? {isActive : true} : {isActive:false}
7+
res.status(200).json(apiKey)
8+
}catch(err:any){
9+
console.log(err.message)
10+
const status = err.status || 500
11+
const errData = err.data || {message: "I can not get the change request activation status"}
12+
res.status(status).send(errData);
13+
}
14+
}
15+
16+
GET.apiDoc = {
17+
summary: "Get Change request Document by id.",
18+
operationId: "getChangeRequest",
19+
parameters: [
20+
{
21+
in: "path",
22+
name: "org",
23+
required: true,
24+
type: "string"
25+
},
26+
{
27+
in: "path",
28+
name: "db",
29+
required: true,
30+
type: "string"
31+
}
32+
],
33+
responses: {
34+
200: {
35+
description: "Return the Change Request Activation Status.",
36+
schema: {
37+
type: "object",
38+
items: {
39+
$ref: "#/definitions/ChangeRequestActivationStatus",
40+
},
41+
},
42+
},
43+
},
44+
};
45+
46+
47+
48+
//return operations;
49+
// };
50+
51+
//export default operation

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import ChangeRequestDB from "../../../../../../core/ChangeRequestDB";
2626
const crId = req.params.changeid
2727
const changeR = new ChangeRequestDB(req)
2828
const apiKey = process.env.OPENAI_KEY
29-
await changeR.changeRequestStatus(crId,req.body.status,req.body.message,apiKey)
30-
res.status(200).send({message:"The change request status has been update"});
29+
const changeDoc = await changeR.changeRequestStatus(crId,req.body.status,req.body.message,apiKey)
30+
res.status(200).send(changeDoc);
3131
}catch(err:any){
3232
console.log(err.message)
3333
const status = err.status || 500
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { Operation } from "express-openapi";
2+
import { Request,Response, } from "express";
3+
import ChangeRequestDB from "../../../../../../../core/ChangeRequestDB";
4+
5+
export const POST: Operation = async(req:Request, res:Response) =>{
6+
try {
7+
const crId = req.params.changeid
8+
const changeR = new ChangeRequestDB(req)
9+
const result = await changeR.addMessage(crId,req.body.message)
10+
res.status(200).json(result)
11+
} catch (err:any) {
12+
//req.context.logger.error(err.message)
13+
const status = err.status || 500
14+
const errData = err.data || { message: 'I can not add a new message', err: err.message }
15+
res.status(status).send(errData)
16+
}
17+
}
18+
19+
20+
POST.apiDoc = {
21+
summary: "Rebase the current change request to the original branch",
22+
operationId: "rebaseChangeRequest",
23+
parameters: [
24+
{
25+
in: "path",
26+
name: "org",
27+
required: true,
28+
type: "string"
29+
},
30+
{
31+
in: "path",
32+
name: "db",
33+
required: true,
34+
type: "string"
35+
},
36+
{
37+
in: "path",
38+
name: "changeid",
39+
required: true,
40+
type: "string"
41+
},
42+
],
43+
responses: {
44+
200: {
45+
description: "Return the change request document with the new message",
46+
},
47+
},
48+
};

src/api/paths/api/tables/{org}/{db}/local/branch/{branch}/index.ts renamed to src/api/paths/api/tables/{org}/{db}/local/{type}/{typeid}/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import GraphqlTableConfig from "../../../../../../../../core/GraphqlTableConfig"
66
export const GET: Operation = async(req:Request, res:Response) =>{
77
try{
88
const connector = new GraphqlTableConfig(req)
9-
const tableConfig = await connector.getSchema(req.params.org, req.params.db, req.params.branch)
9+
const tableConfig = await connector.getSchema(req.params.org, req.params.db, req.params.type, req.params.typeid)
1010
res.json(tableConfig)
1111
}catch(err:any){
1212
console.log(err.message)
1313
const status = err.status || 500
14-
const errData = err.data || {message: "I can not get the change requests list"}
14+
const errData = err.data || {message: "I can not return the tables configuration"}
1515
res.status(status).send(errData);
1616
}
1717
}
@@ -34,7 +34,13 @@ GET.apiDoc = {
3434
},
3535
{
3636
in: "path",
37-
name: "branch",
37+
name: "type",
38+
required: true,
39+
type: "string"
40+
},
41+
{
42+
in: "path",
43+
name: "typeid",
3844
required: true,
3945
type: "string"
4046
},

0 commit comments

Comments
 (0)