1
- import Router from "koa-router"
1
+ import { runChecksOnRun } from "@/src/checks/runChecks"
2
+ import { checkAccess } from "@/src/utils/authorization"
3
+ import { calcRunCost } from "@/src/utils/calcCost"
4
+ import { getReadableDateTime } from "@/src/utils/date"
2
5
import sql from "@/src/utils/db"
3
6
import Context from "@/src/utils/koa"
4
- import { getReadableDateTime } from "@/src/utils/date"
5
- import { runEval } from "./utils"
6
- import { getEvaluation } from "./utils"
7
- import { calcRunCost } from "@/src/utils/calcCost"
8
- import { runChecksOnRun } from "@/src/checks/runChecks"
7
+ import Router from "koa-router"
8
+ import { RunEvent } from "lunary/types"
9
9
import PQueue from "p-queue"
10
10
import { PassThrough } from "stream"
11
- import { checkAccess } from "@/src/utils/authorization"
12
- import { RunEvent } from "lunary/types"
11
+ import { runEval } from "./utils"
13
12
14
13
const evaluations = new Router ( { prefix : "/evaluations" } )
15
14
@@ -20,7 +19,7 @@ evaluations.post(
20
19
checkAccess ( "evaluations" , "create" ) ,
21
20
async ( ctx : Context ) => {
22
21
const { name, datasetId, checklistId, providers } = ctx . request . body as any
23
- const { userId, projectId } = ctx . state
22
+ const { userId, projectId, orgId } = ctx . state
24
23
25
24
ctx . request . socket . setTimeout ( 0 )
26
25
ctx . request . socket . setNoDelay ( true )
@@ -37,6 +36,12 @@ evaluations.post(
37
36
timeout : 10000 ,
38
37
} )
39
38
39
+ const [ { plan } ] =
40
+ await sql `select plan, eval_allowance from org where id = ${ orgId } `
41
+ if ( plan === "free" ) {
42
+ ctx . throw ( 403 , "You can't create evaluations on the free plan." )
43
+ }
44
+
40
45
// TODO: transactions, but not working with because of nesting
41
46
const evaluationToInsert = {
42
47
name : name ? name : `Evaluation of ${ getReadableDateTime ( ) } ` ,
0 commit comments