enhancment complete with phase 10
This commit is contained in:
1 parent
2c4927478a
commit
6adb541967
44 files changed
+7820
-845
No files matched your search
@@ -21,8 +21,13 @@ import {
|
||||
desc,
|
||||
asc,
|
||||
sql,
|
||||
inArray,
|
||||
gte,
|
||||
lte,
|
||||
or,
|
||||
like,
|
||||
} from "@fitai/database";
|
||||
import { SQL, or, like, inArray, gte, lte } from "drizzle-orm";
|
||||
import { SQL } from "drizzle-orm";
|
||||
import type { SortConfig, FilterCondition } from "../filtering";
|
||||
import { buildWhereConditions, buildSearchCondition } from "../filtering";
|
||||
import log from "../logger";
|
||||
@@ -643,6 +648,17 @@ export class DrizzleDatabase implements IDatabase {
|
||||
return result ? this.mapClient(result) : null;
|
||||
}
|
||||
|
||||
async getClientsByUserIds(userIds: string[]): Promise<Client[]> {
|
||||
if (userIds.length === 0) return [];
|
||||
|
||||
const results = await this.db
|
||||
.select()
|
||||
.from(clients)
|
||||
.where(inArray(clients.userId, userIds))
|
||||
.all();
|
||||
return results.map((r) => this.mapClient(r));
|
||||
}
|
||||
|
||||
async getAllClients(): Promise<Client[]> {
|
||||
const results = await this.db
|
||||
.select()
|
||||
@@ -1011,6 +1027,36 @@ export class DrizzleDatabase implements IDatabase {
|
||||
return history.find((a) => !a.checkOutTime) || null;
|
||||
}
|
||||
|
||||
async getAttendanceHistoriesByUserIds(
|
||||
userIds: string[],
|
||||
): Promise<Attendance[]> {
|
||||
if (userIds.length === 0) return [];
|
||||
|
||||
const results = await this.db
|
||||
.select()
|
||||
.from(attendance)
|
||||
.where(inArray(attendance.userId, userIds))
|
||||
.orderBy(desc(attendance.checkInTime))
|
||||
.all();
|
||||
return results.map((r) => this.mapAttendance(r));
|
||||
}
|
||||
|
||||
async getActiveCheckInsByUserIds(userIds: string[]): Promise<Attendance[]> {
|
||||
if (userIds.length === 0) return [];
|
||||
|
||||
// Get all attendance records for these users and filter for active check-ins
|
||||
const results = await this.db
|
||||
.select()
|
||||
.from(attendance)
|
||||
.where(inArray(attendance.userId, userIds))
|
||||
.all();
|
||||
|
||||
// Filter for active check-ins (no checkout time)
|
||||
return results
|
||||
.filter((r) => !r.checkOutTime)
|
||||
.map((r) => this.mapAttendance(r));
|
||||
}
|
||||
|
||||
// Recommendation operations
|
||||
async createRecommendation(
|
||||
data: Omit<Recommendation, "createdAt" | "approvedAt" | "approvedBy">,
|
||||
@@ -1079,6 +1125,20 @@ export class DrizzleDatabase implements IDatabase {
|
||||
return result ? this.mapRecommendation(result) : null;
|
||||
}
|
||||
|
||||
async getRecommendationsByUserIds(
|
||||
userIds: string[],
|
||||
): Promise<Recommendation[]> {
|
||||
if (userIds.length === 0) return [];
|
||||
|
||||
const results = await this.db
|
||||
.select()
|
||||
.from(recommendations)
|
||||
.where(inArray(recommendations.userId, userIds))
|
||||
.orderBy(desc(recommendations.createdAt))
|
||||
.all();
|
||||
return results.map((r) => this.mapRecommendation(r));
|
||||
}
|
||||
|
||||
// Fitness Goals operations
|
||||
async createFitnessGoal(
|
||||
goalData: Omit<FitnessGoal, "createdAt" | "updatedAt">,
|
||||
@@ -1190,6 +1250,18 @@ export class DrizzleDatabase implements IDatabase {
|
||||
return this.getFitnessGoalById(id);
|
||||
}
|
||||
|
||||
async getFitnessGoalsByUserIds(userIds: string[]): Promise<FitnessGoal[]> {
|
||||
if (userIds.length === 0) return [];
|
||||
|
||||
const results = await this.db
|
||||
.select()
|
||||
.from(fitnessGoals)
|
||||
.where(inArray(fitnessGoals.userId, userIds))
|
||||
.orderBy(desc(fitnessGoals.createdAt))
|
||||
.all();
|
||||
return results.map((r) => this.mapFitnessGoal(r));
|
||||
}
|
||||
|
||||
async getDashboardStats(): Promise<{
|
||||
totalUsers: number;
|
||||
activeClients: number;
|
||||
|
||||
Reference in new issue
Block a user