1- import TerminusClient , { WOQLClient , WOQL } from "@terminusdb/terminusdb-client"
1+ import TerminusClient , { WOQLClient , WOQL , AccessControl } from "@terminusdb/terminusdb-client"
22import { DbDetails , DocParamsGet , DocParamsPut , DiffObject } from "@terminusdb/terminusdb-client/dist/typescript/lib/typedef"
33import { Request } from "express"
44import * as typeDef from "./typeDef"
55import { ApiError } from "./ApiError"
6- const server : string = process . env . SERVER_ENDPOINT || "http://127.0.0.1:6363"
7-
86import * as IndexClient from './IndexClient'
97
108import dbSchema from '../../change_request_schema.json'
119import { doc } from "@terminusdb/terminusdb-client/dist/typescript/lib/woql"
1210//import {v4 as uuidv4} from 'uuid';
1311const { v4 : uuidv4 } = require ( 'uuid' ) ;
1412
15- const endpoint = process . env . SERVER_ENDPOINT || ""
16- const key = process . env . USER_KEY || ""
17- const CROrg = process . env . CR_TEARM_NAME || ""
18- const user = process . env . USER_NAME || ""
13+ const endpoint : string = process . env . SERVER_ENDPOINT || "http://127.0.0.1:6363 "
14+ const key = process . env . USER_KEY || "root "
15+ const CROrg = process . env . CR_TEAM_NAME || "terminusCR "
16+ const user = process . env . USER_NAME || "admin "
1917
2018
2119const logger = {
@@ -38,6 +36,7 @@ const logger = {
3836}
3937class ChangeRequestDB {
4038 client : WOQLClient ;
39+ accessControl : AccessControl ;
4140 request : Request
4241 user : string | undefined
4342 password : string | undefined
@@ -60,6 +59,7 @@ class ChangeRequestDB {
6059 this . logger = logger //req.context.logger
6160 // every dataproduct has the related change_request database
6261 this . changeRequestDbName = `${ TerminusClient . UTILS . encodeURISegment ( this . orgName ) } __${ this . dbName } __CR`
62+ this . accessControl = new AccessControl ( endpoint , { key : key , user : user } )
6363 this . client . db ( this . changeRequestDbName )
6464 }
6565
@@ -84,6 +84,14 @@ class ChangeRequestDB {
8484 }
8585 }
8686
87+ async createTeam ( ) {
88+ try {
89+ await this . accessControl . createOrganization ( CROrg )
90+ } catch ( err ) {
91+ // the team already exists
92+ }
93+ }
94+
8795 async createCRDatabase ( ) {
8896 try {
8997 if ( this . changeRequestDbName ) {
0 commit comments