1- export type RouteAnnotation = {
2- key : string ;
3- value : string ;
4- } ;
1+ import { Pool } from 'mariadb' ;
2+ import { query } from '../../util/db' ;
3+ import { Sql } from './sql' ;
4+ import { Helpers as environmentHelpers } from '../environment/helpers' ;
5+ import { Helpers as projectHelpers } from '../project/helpers' ;
56
6- export type RouteAnnotations = RouteAnnotation [ ] ;
7+ import { RouteAnnotations , PathRoutes } from './types' ;
8+
9+ export const Helpers = ( sqlClientPool : Pool ) => {
10+ const removeAllRoutesFromEnvironment = async ( environmentId : number ) => {
11+ await query (
12+ sqlClientPool ,
13+ Sql . removeAllRoutesFromEnvironment ( environmentId )
14+ )
15+ }
16+ const deleteEnvironmentAutogeneratedRoutes = async ( environmentId : number ) => {
17+ await query (
18+ sqlClientPool ,
19+ Sql . deleteEnvironmentAutogeneratedRoutes ( environmentId )
20+ )
21+ }
22+ const removeRouteFromEnvironment = async ( domain : string , environmentId : number ) => {
23+ const routes = await query (
24+ sqlClientPool ,
25+ Sql . selectRoutesByDomainAndEnvironmentID ( domain , environmentId )
26+ )
27+ if ( routes . length == 0 ) {
28+ throw Error ( `Route doesn't exist on this environment` )
29+ }
30+ const route = routes [ 0 ]
31+ if ( route . autogenerated == true ) {
32+ throw Error ( `Cannot remove autogenerated routes` )
33+ }
34+ await query (
35+ sqlClientPool ,
36+ Sql . updateRoute ( {
37+ id : route . id ,
38+ patch : {
39+ environment : null ,
40+ service : null ,
41+ pathRoutes : null ,
42+ }
43+ } )
44+ ) ;
45+ return route . id
46+ } ;
47+
48+ return {
49+ removeAllRoutesFromEnvironment,
50+ deleteEnvironmentAutogeneratedRoutes,
51+ removeRouteFromEnvironment,
52+ }
53+ }
754
855export function addAnnotation (
956 annotations : RouteAnnotations ,
@@ -30,13 +77,6 @@ export function removeAnnotation(
3077 ) ;
3178}
3279
33- export type PathRoute = {
34- toService : string ;
35- path : string ;
36- } ;
37-
38- export type PathRoutes = PathRoute [ ] ;
39-
4080export function addServicePathRoute (
4181 pathRoutes : PathRoutes ,
4282 newToService : string ,
0 commit comments