finished hooking up promotion history
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { BatchPromotion, BatchPromotionMember } from "@app/shared/schemas/promotionSchema";
|
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 pool from "../db";
|
||||||
import { PagedData } from "@app/shared/types/pagination";
|
import { PagedData } from "@app/shared/types/pagination";
|
||||||
import { toDateTime } from "@app/shared/utils/time";
|
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
|
DATE(start_date) AS entry_day
|
||||||
FROM
|
FROM
|
||||||
members_ranks
|
members_ranks
|
||||||
|
WHERE reason = 'Rank Change'
|
||||||
GROUP BY
|
GROUP BY
|
||||||
entry_day
|
entry_day
|
||||||
ORDER BY
|
ORDER BY
|
||||||
@@ -75,6 +76,7 @@ export async function getPromotionHistorySummary(page: number = 1, pageSize: num
|
|||||||
(
|
(
|
||||||
SELECT DISTINCT DATE(start_date)
|
SELECT DISTINCT DATE(start_date)
|
||||||
FROM members_ranks
|
FROM members_ranks
|
||||||
|
WHERE reason = 'Rank Change'
|
||||||
) AS grouped_days;`))[0]);
|
) AS grouped_days;`))[0]);
|
||||||
|
|
||||||
console.log(loaCount);
|
console.log(loaCount);
|
||||||
@@ -84,28 +86,23 @@ export async function getPromotionHistorySummary(page: number = 1, pageSize: num
|
|||||||
return output;
|
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
|
const dayString = toDateTime(day);
|
||||||
// This assumes pool.query is used with a database that accepts this format for comparison.
|
|
||||||
const dayString = day.toISOString().split('T')[0];
|
|
||||||
|
|
||||||
// SQL query to fetch all records from members_unit for the specified day
|
// SQL query to fetch all records from members_unit for the specified day
|
||||||
let sql = `
|
let sql = `
|
||||||
SELECT
|
SELECT
|
||||||
member_id,
|
mr.member_id,
|
||||||
unit_id AS rank_id, -- Using unit_id as a proxy for rank_id based on the data structure
|
mr.created_by_id,
|
||||||
start_date
|
r.short_name
|
||||||
FROM
|
FROM members_ranks AS mr
|
||||||
members_unit
|
LEFT JOIN ranks AS r ON r.id = mr.rank_id
|
||||||
WHERE
|
WHERE DATE(mr.start_date) = ? && mr.reason = 'Rank Change'
|
||||||
DATE(start_date) = ?
|
ORDER BY mr.start_date ASC;
|
||||||
ORDER BY
|
|
||||||
start_date ASC;
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
let batchPromotion = await pool.query(sql, [dayString]) as PromotionDetails[];
|
||||||
let batchPromotion = await pool.query(sql, [dayString]) as BatchPromotion[];
|
|
||||||
|
|
||||||
return batchPromotion;
|
return batchPromotion;
|
||||||
}
|
}
|
||||||
@@ -8,4 +8,10 @@ export type Rank = {
|
|||||||
|
|
||||||
export interface PromotionSummary {
|
export interface PromotionSummary {
|
||||||
entry_day: Date;
|
entry_day: Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PromotionDetails {
|
||||||
|
member_id: number;
|
||||||
|
short_name: string;
|
||||||
|
created_by_id: number;
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { BatchPromotion, BatchPromotionMember } from '@shared/schemas/promotionSchema';
|
import { BatchPromotion, BatchPromotionMember } from '@shared/schemas/promotionSchema';
|
||||||
import { PagedData } from '@shared/types/pagination';
|
import { PagedData } from '@shared/types/pagination';
|
||||||
import { PromotionSummary, Rank } from '@shared/types/rank'
|
import { PromotionDetails, PromotionSummary, Rank } from '@shared/types/rank'
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const addr = import.meta.env.VITE_APIHOST;
|
const addr = import.meta.env.VITE_APIHOST;
|
||||||
@@ -60,8 +60,9 @@ export async function getPromoHistory(page?: number, pageSize?: number): Promise
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getPromotionsOnDay(day: Date): Promise<BatchPromotionMember[]> {
|
export async function getPromotionsOnDay(day: Date): Promise<PromotionDetails[]> {
|
||||||
const res = await fetch(`${addr}/memberRanks/${day}`, {
|
console.log(day.toISOString());
|
||||||
|
const res = await fetch(`${addr}/memberRanks/${day.toISOString()}`, {
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -71,8 +71,11 @@ function formatDate(date: Date): string {
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div class="flex flex-col max-w-7xl w-full">
|
||||||
<div class="max-w-7xl w-full mx-auto">
|
<p class="scroll-m-20 text-2xl font-semibold tracking-tight mb-3">
|
||||||
|
Promotion History
|
||||||
|
</p>
|
||||||
|
<div class="w-full mx-auto">
|
||||||
<Table>
|
<Table>
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { getPromotionsOnDay } from '@/api/rank';
|
import { getPromotionsOnDay } from '@/api/rank';
|
||||||
import { BatchPromotionMember } from '@shared/schemas/promotionSchema';
|
|
||||||
import { onMounted, ref } from 'vue';
|
import { onMounted, ref } from 'vue';
|
||||||
import MemberCard from '../members/MemberCard.vue';
|
import MemberCard from '../members/MemberCard.vue';
|
||||||
import Spinner from '../ui/spinner/Spinner.vue';
|
import Spinner from '../ui/spinner/Spinner.vue';
|
||||||
|
import { PromotionDetails } from '@shared/types/rank';
|
||||||
|
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
date: Date
|
date: Date
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const promoList = ref<BatchPromotionMember[]>();
|
const promoList = ref<PromotionDetails[]>();
|
||||||
const loading = ref(true);
|
const loading = ref(true);
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
@@ -33,14 +33,14 @@ onMounted(async () => {
|
|||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr v-for="p in promoList" :key="p.member_id" class="border-b transition-colors">
|
<tr v-for="p in promoList" :key="p.member_id" class="border-b transition-colors">
|
||||||
<td class="px-4 py-4">
|
<td class="px-2 py-2">
|
||||||
<MemberCard :member-id="p.member_id" />
|
<MemberCard :member-id="p.member_id" />
|
||||||
</td>
|
</td>
|
||||||
<td class="px-4 py-4 text-sm">
|
<td class="px-4 py-2 text-sm">
|
||||||
{{ p.rank_id }}
|
{{ p.short_name }}
|
||||||
</td>
|
</td>
|
||||||
<td class="px-4 py-4 text-sm text-right">
|
<td class="px-2 py-2 text-sm text-right">
|
||||||
guy1
|
<MemberCard :member-id="p.created_by_id" />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
Reference in New Issue
Block a user