UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

2 lines 1.13 kB
import{copy as e}from"../../../libs/i18n/copy.mjs";import t from"../../../libs/repositories/ai-generations.mjs";import{formatDbTimestamp as n,getDateKey as r}from"../helpers/date-helpers.mjs";import i from"../helpers/build-usage-chart-series.mjs";import a from"../helpers/normalize-usage-chart-query.mjs";import{formatAiUsageFeatureLabel as o}from"../../../libs/formatters/ai-usage.mjs";const s=async(s,c)=>{let l=a(c.query);if(!l)return{error:{type:`basic`,status:400,message:e(`server:core.ai.usage.chart.invalid.date.range`)},data:void 0};let u=await new t(s.db.client,s.config.db).selectUsageChartRows({startDate:n(l.start),endDate:n(l.endExclusive),featureKey:l.featureKey,tenantKey:s.request.tenantKey,validation:{enabled:!0}});if(u.error)return u;let d=i({rows:u.data,metrics:l.metrics,start:l.start,end:l.end});return{error:void 0,data:{dimension:l.dimension,metrics:l.metrics,startDate:r(l.start),endDate:r(l.end),currency:d.currency,feature:l.featureKey?{key:l.featureKey,label:o({featureKey:l.featureKey,translate:s.translate})}:null,series:d.series}}};export{s as default}; //# sourceMappingURL=get-usage-chart.mjs.map