chore: dashboard report, admin route decorator and guard

This commit is contained in:
Matin
2025-02-25 09:10:13 +03:30
parent 17e39fde09
commit 37b8e00445
5 changed files with 41 additions and 8 deletions
@@ -1,4 +1,5 @@
import { BadRequestException, Injectable } from "@nestjs/common";
import dayjs from "dayjs";
// eslint-disable-next-line import/no-named-as-default
import Decimal from "decimal.js";
import { DataSource, In } from "typeorm";
@@ -371,12 +372,10 @@ export class SubscriptionsService {
}
async getPlansSalesCountByDaysInWeek() {
const now = new Date();
const daysSinceStart = now.getDay(); // Remove the +1 and % 7
const startOfWeek = new Date(now);
startOfWeek.setDate(now.getDate() - daysSinceStart);
const endOfWeek = new Date(startOfWeek);
endOfWeek.setDate(startOfWeek.getDate() + 6);
const startOfWeek = dayjs().startOf("week").toDate();
const endOfWeek = dayjs().endOf("week").toDate();
console.log(startOfWeek, endOfWeek);
const sales = await this.userSubscriptionsRepository
.createQueryBuilder("userSubscription")
@@ -392,7 +391,7 @@ export class SubscriptionsService {
const salesByDay = Array(7).fill(0);
sales.forEach((sale) => {
const day = new Date(sale.date).getDay(); // Remove the +1 and % 7
const day = (dayjs(sale.date).day() + 1) % 7;
salesByDay[day] = parseInt(sale.count);
});