finished hooking up promotion history
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { BatchPromotion, BatchPromotionMember } from "@app/shared/schemas/promotionSchema";
|
||||
import { PromotionSummary } from "@app/shared/types/rank"
|
||||
import { PromotionDetails, PromotionSummary } from "@app/shared/types/rank"
|
||||
import pool from "../db";
|
||||
import { PagedData } from "@app/shared/types/pagination";
|
||||
import { toDateTime } from "@app/shared/utils/time";
|
||||
@@ -61,6 +61,7 @@ export async function getPromotionHistorySummary(page: number = 1, pageSize: num
|
||||
DATE(start_date) AS entry_day
|
||||
FROM
|
||||
members_ranks
|
||||
WHERE reason = 'Rank Change'
|
||||
GROUP BY
|
||||
entry_day
|
||||
ORDER BY
|
||||
@@ -75,6 +76,7 @@ export async function getPromotionHistorySummary(page: number = 1, pageSize: num
|
||||
(
|
||||
SELECT DISTINCT DATE(start_date)
|
||||
FROM members_ranks
|
||||
WHERE reason = 'Rank Change'
|
||||
) AS grouped_days;`))[0]);
|
||||
|
||||
console.log(loaCount);
|
||||
@@ -84,28 +86,23 @@ export async function getPromotionHistorySummary(page: number = 1, pageSize: num
|
||||
return output;
|
||||
}
|
||||
|
||||
export async function getPromotionsOnDay(day: Date): Promise<BatchPromotion[]> {
|
||||
export async function getPromotionsOnDay(day: Date): Promise<PromotionDetails[]> {
|
||||
|
||||
// Convert the Date object to a 'YYYY-MM-DD' string for the SQL filter
|
||||
// This assumes pool.query is used with a database that accepts this format for comparison.
|
||||
const dayString = day.toISOString().split('T')[0];
|
||||
const dayString = toDateTime(day);
|
||||
|
||||
// SQL query to fetch all records from members_unit for the specified day
|
||||
let sql = `
|
||||
SELECT
|
||||
member_id,
|
||||
unit_id AS rank_id, -- Using unit_id as a proxy for rank_id based on the data structure
|
||||
start_date
|
||||
FROM
|
||||
members_unit
|
||||
WHERE
|
||||
DATE(start_date) = ?
|
||||
ORDER BY
|
||||
start_date ASC;
|
||||
SELECT
|
||||
mr.member_id,
|
||||
mr.created_by_id,
|
||||
r.short_name
|
||||
FROM members_ranks AS mr
|
||||
LEFT JOIN ranks AS r ON r.id = mr.rank_id
|
||||
WHERE DATE(mr.start_date) = ? && mr.reason = 'Rank Change'
|
||||
ORDER BY mr.start_date ASC;
|
||||
`;
|
||||
|
||||
|
||||
let batchPromotion = await pool.query(sql, [dayString]) as BatchPromotion[];
|
||||
let batchPromotion = await pool.query(sql, [dayString]) as PromotionDetails[];
|
||||
|
||||
return batchPromotion;
|
||||
}
|
||||
Reference in New Issue
Block a user