clean up some chart related things
This commit is contained in:
@@ -6,7 +6,7 @@ import type {
|
|||||||
IInterval,
|
IInterval,
|
||||||
} from '@/types';
|
} from '@/types';
|
||||||
import { alphabetIds } from '@/utils/constants';
|
import { alphabetIds } from '@/utils/constants';
|
||||||
import { average, max, min, round, sum } from '@/utils/math';
|
import { round } from '@/utils/math';
|
||||||
import * as mathjs from 'mathjs';
|
import * as mathjs from 'mathjs';
|
||||||
import { sort } from 'ramda';
|
import { sort } from 'ramda';
|
||||||
|
|
||||||
@@ -3,12 +3,12 @@ import type { IChartEvent, IChartInput, IChartRange } from '@/types';
|
|||||||
import { getDaysOldDate } from '@/utils/date';
|
import { getDaysOldDate } from '@/utils/date';
|
||||||
import { average, max, min, round, sum } from '@/utils/math';
|
import { average, max, min, round, sum } from '@/utils/math';
|
||||||
import { zChartInput } from '@/utils/validation';
|
import { zChartInput } from '@/utils/validation';
|
||||||
import { flatten, map, pathOr, pipe, prop, sort, uniq } from 'ramda';
|
import { flatten, map, pipe, prop, sort, uniq } from 'ramda';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { chQuery } from '@mixan/db';
|
import { chQuery } from '@mixan/db';
|
||||||
|
|
||||||
import { getChartData, withFormula } from './chart.formula';
|
import { getChartData, withFormula } from './chart.helpers';
|
||||||
|
|
||||||
type PreviousValue = {
|
type PreviousValue = {
|
||||||
value: number;
|
value: number;
|
||||||
@@ -176,16 +176,6 @@ export const chartRouter = createTRPCRouter({
|
|||||||
const promises = [getSeriesFromEvents(input)];
|
const promises = [getSeriesFromEvents(input)];
|
||||||
|
|
||||||
if (input.previous) {
|
if (input.previous) {
|
||||||
console.log('------->P R E V I O U S');
|
|
||||||
console.log({
|
|
||||||
startDate: new Date(
|
|
||||||
new Date(current.startDate).getTime() - diff
|
|
||||||
).toISOString(),
|
|
||||||
endDate: new Date(
|
|
||||||
new Date(current.endDate).getTime() - diff
|
|
||||||
).toISOString(),
|
|
||||||
});
|
|
||||||
|
|
||||||
promises.push(
|
promises.push(
|
||||||
getSeriesFromEvents({
|
getSeriesFromEvents({
|
||||||
...input,
|
...input,
|
||||||
@@ -396,20 +386,21 @@ async function getSeriesFromEvents(input: IChartInput) {
|
|||||||
function getDatesFromRange(range: IChartRange) {
|
function getDatesFromRange(range: IChartRange) {
|
||||||
if (range === 'today') {
|
if (range === 'today') {
|
||||||
const startDate = new Date();
|
const startDate = new Date();
|
||||||
const endDate = new Date().toISOString();
|
const endDate = new Date();
|
||||||
startDate.setHours(0, 0, 0, 0);
|
startDate.setUTCHours(0, 0, 0, 0);
|
||||||
|
endDate.setUTCHours(23, 59, 59, 999);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
startDate: startDate.toISOString(),
|
startDate: startDate.toUTCString(),
|
||||||
endDate: endDate,
|
endDate: endDate.toUTCString(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (range === '30min' || range === '1h') {
|
if (range === '30min' || range === '1h') {
|
||||||
const startDate = new Date(
|
const startDate = new Date(
|
||||||
Date.now() - 1000 * 60 * (range === '30min' ? 30 : 60)
|
Date.now() - 1000 * 60 * (range === '30min' ? 30 : 60)
|
||||||
).toISOString();
|
).toUTCString();
|
||||||
const endDate = new Date().toISOString();
|
const endDate = new Date().toUTCString();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
startDate,
|
startDate,
|
||||||
@@ -440,7 +431,7 @@ function getDatesFromRange(range: IChartRange) {
|
|||||||
const endDate = new Date();
|
const endDate = new Date();
|
||||||
endDate.setUTCHours(23, 59, 59, 999);
|
endDate.setUTCHours(23, 59, 59, 999);
|
||||||
return {
|
return {
|
||||||
startDate: startDate.toISOString(),
|
startDate: startDate.toUTCString(),
|
||||||
endDate: endDate.toISOString(),
|
endDate: endDate.toUTCString(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,9 @@
|
|||||||
import { createTRPCRouter, protectedProcedure } from '@/server/api/trpc';
|
import { createTRPCRouter, protectedProcedure } from '@/server/api/trpc';
|
||||||
import { db } from '@/server/db';
|
|
||||||
import { hashPassword, verifyPassword } from '@/server/services/hash.service';
|
|
||||||
import { transformUser } from '@/server/services/user.service';
|
import { transformUser } from '@/server/services/user.service';
|
||||||
import { clerkClient } from '@clerk/nextjs';
|
import { clerkClient } from '@clerk/nextjs';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
export const userRouter = createTRPCRouter({
|
export const userRouter = createTRPCRouter({
|
||||||
current: protectedProcedure.query(({ ctx }) => {
|
|
||||||
return db.user.findUniqueOrThrow({
|
|
||||||
where: {
|
|
||||||
id: ctx.session.user.id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
update: protectedProcedure
|
update: protectedProcedure
|
||||||
.input(
|
.input(
|
||||||
z.object({
|
z.object({
|
||||||
|
|||||||
Reference in New Issue
Block a user