Skip to content

Commit

Permalink
Added creationDate column to student and user tables bcs Accounts Wit…
Browse files Browse the repository at this point in the history
…hout Family table needs it
  • Loading branch information
Benjyhy committed Oct 17, 2024
1 parent 51d8747 commit 954db1d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 4 deletions.
5 changes: 4 additions & 1 deletion server/entities/student.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Entity, Column, ManyToOne, OneToMany, PrimaryGeneratedColumn, JoinColumn } from 'typeorm';
import { Entity, Column, ManyToOne, OneToMany, PrimaryGeneratedColumn, JoinColumn, CreateDateColumn } from 'typeorm';

import { Classroom } from './classroom';
import { UserToStudent } from './userToStudent';
Expand All @@ -8,6 +8,9 @@ export class Student {
@PrimaryGeneratedColumn()
public id: number;

@CreateDateColumn()
createdAt: Date;

@Column({ type: 'varchar', length: 100, nullable: true })
public firstname: string;

Expand Down
5 changes: 4 additions & 1 deletion server/entities/user.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Column, Entity, PrimaryGeneratedColumn, ManyToOne, JoinColumn, OneToMany, ManyToMany, JoinTable } from 'typeorm';
import { Column, Entity, PrimaryGeneratedColumn, ManyToOne, JoinColumn, OneToMany, ManyToMany, JoinTable, CreateDateColumn } from 'typeorm';

import type { Country } from '../../types/country.type';
import { UserType } from '../../types/user.type';
Expand All @@ -19,6 +19,9 @@ export class User implements UserInterface {
@PrimaryGeneratedColumn()
public id: number;

@CreateDateColumn()
createdAt: Date;

@Column({ type: 'varchar', length: 255, unique: true })
public email: string;

Expand Down
3 changes: 2 additions & 1 deletion server/stats/villageStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const getFamiliesWithoutAccount = async (villageId: number) => {
'student.firstname AS student_firstname',
'student.lastname AS student_lastname',
'student.id AS student_id',
'student.createdAt as student_creation_date',
'village.name AS village_name',
])
.getRawMany();
Expand All @@ -65,7 +66,7 @@ export const getFloatingAccounts = async (villageId: number) => {
.where('user.villageId = :villageId', { villageId })
.andWhere('user.hasStudentLinked = 0')
.andWhere('user.type = 4')
.select(['user.id', 'user.firstname', 'user.lastname', 'user.language', 'user.email'])
.select(['user.id', 'user.firstname', 'user.lastname', 'user.language', 'user.email', 'user.createdAt'])
.getMany();
return floatingAccounts;
};
3 changes: 2 additions & 1 deletion src/components/admin/dashboard-statistics/VillageStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import styles from './styles/charts.module.css';
import { useGetVillagesStats } from 'src/api/statistics/statistics.get';
import { useCountries } from 'src/services/useCountries';
import { useVillages } from 'src/services/useVillages';
import { formatDate } from 'src/utils';
import type { FamiliesWithoutAccount, OneVillageTableRow } from 'types/statistics.type';
import type { VillageFilter } from 'types/village.type';

Expand Down Expand Up @@ -96,7 +97,7 @@ const VillageStats = () => {
vm: row.village_name,
classroom: row.classroom_name,
country: row.classroom_country,
creationDate: 'À venir',
creationDate: row.student_creation_date ? formatDate(row.student_creation_date) : 'Donnée non disponible',
};
});
}
Expand Down
9 changes: 9 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ export function countryToFlag(isoCode: string): string {
: isoCode;
}

export function formatDate(isoString: string): string {
const date = new Date(isoString);
const day = date.getUTCDate().toString().padStart(2, '0');
const month = (date.getUTCMonth() + 1).toString().padStart(2, '0');
const year = date.getUTCFullYear();
const formattedDate = `${day}/${month}/${year}`;
return formattedDate;
}

/**
* Returns a random token. Browser only!
* @param length length of the returned token.
Expand Down
2 changes: 2 additions & 0 deletions types/statistics.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface FamiliesWithoutAccount {
student_id: number;
student_firstname: string;
student_lastname: string;
student_creation_date: string | null;
village_name: string;
classroom_name: string;
classroom_country: string;
Expand All @@ -49,6 +50,7 @@ export interface FloatingAccount {
firstname: string;
lastname: string;
language: string;
createdAt: string | null;
}

export interface OneVillageTableRow {
Expand Down

0 comments on commit 954db1d

Please sign in to comment.