From 854f85a9a2a02a6821bbb9d2ca6f6a175f6f642d Mon Sep 17 00:00:00 2001 From: Neo Ryo Date: Thu, 30 May 2024 10:34:50 +0200 Subject: [PATCH 1/3] mig ok --- server/entities/activity.ts | 3 +++ .../1717055850587-publishedAtActivityField.ts | 20 +++++++++++++++++++ src/components/admin/NewAdminNavigation.tsx | 18 +++++++++++++---- 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 server/migrations/1717055850587-publishedAtActivityField.ts diff --git a/server/entities/activity.ts b/server/entities/activity.ts index 0e7ccc6f3..fa6318c18 100644 --- a/server/entities/activity.ts +++ b/server/entities/activity.ts @@ -50,6 +50,9 @@ export class Activity implements ActivityInterface { @CreateDateColumn() public createDate: Date; + @CreateDateColumn() + public publishDate: Date; + @UpdateDateColumn() public updateDate: Date; diff --git a/server/migrations/1717055850587-publishedAtActivityField.ts b/server/migrations/1717055850587-publishedAtActivityField.ts new file mode 100644 index 000000000..a827254c8 --- /dev/null +++ b/server/migrations/1717055850587-publishedAtActivityField.ts @@ -0,0 +1,20 @@ +import type { MigrationInterface, QueryRunner } from 'typeorm'; + +export class PublishedAtActivityField1717055850587 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + const activityTable = await queryRunner.getTable('activity'); + if (!activityTable?.columns.find((col) => col.name === 'publishDate')) { + await queryRunner.query(`ALTER TABLE activity + ADD COLUMN publishDate TIMESTAMP`); + await queryRunner.query(`UPDATE activity SET publishDate = activity.createDate WHERE status = 0;`); + } + } + + public async down(queryRunner: QueryRunner): Promise { + const activityTable = await queryRunner.getTable('activity'); + if (activityTable?.columns.find((col) => col.name === 'publishDate')) { + await queryRunner.query(`ALTER TABLE activity + DROP COLUMN publishDate`); + } + } +} diff --git a/src/components/admin/NewAdminNavigation.tsx b/src/components/admin/NewAdminNavigation.tsx index d2946f9d9..2a363d1af 100644 --- a/src/components/admin/NewAdminNavigation.tsx +++ b/src/components/admin/NewAdminNavigation.tsx @@ -58,10 +58,20 @@ export const NewAdminNavigation = () => { const tabs: Tab[] = [ { path: '/admin/newportal/create', label: 'Créer', Icon: CreerIcon, rights: [UserType.ADMIN, UserType.SUPER_ADMIN, UserType.MEDIATOR] }, - { path: '/admin/newportal/publish', label: 'Publier', Icon: PublierIcon, rights: [UserType.ADMIN] }, - { path: '/admin/newportal/manage', label: 'Gérer', Icon: GererIcon, rights: [UserType.ADMIN] }, - { path: '/admin/newportal/analyze', label: 'Analyser', Icon: AnalyserIcon, rights: [UserType.ADMIN, UserType.OBSERVATOR, UserType.MEDIATOR] }, - { path: '/admin/newportal/medialibrary', label: 'Médiathèque', Icon: MediathequeIcon, rights: [UserType.ADMIN, UserType.MEDIATOR] }, + { path: '/admin/newportal/publish', label: 'Publier', Icon: PublierIcon, rights: [UserType.ADMIN, UserType.SUPER_ADMIN] }, + { path: '/admin/newportal/manage', label: 'Gérer', Icon: GererIcon, rights: [UserType.ADMIN, UserType.SUPER_ADMIN] }, + { + path: '/admin/newportal/analyze', + label: 'Analyser', + Icon: AnalyserIcon, + rights: [UserType.SUPER_ADMIN, UserType.ADMIN, UserType.OBSERVATOR, UserType.MEDIATOR], + }, + { + path: '/admin/newportal/medialibrary', + label: 'Médiathèque', + Icon: MediathequeIcon, + rights: [UserType.SUPER_ADMIN, UserType.ADMIN, UserType.MEDIATOR], + }, ]; const onTabClick = (label: string) => { From a57fa57e640957a14b9c75fd1b7b2aa15d41b4f3 Mon Sep 17 00:00:00 2001 From: Neo Ryo Date: Thu, 30 May 2024 14:21:21 +0200 Subject: [PATCH 2/3] activityCard --- server/manager/activity.ts | 2 +- src/components/activities/ActivityCard/index.tsx | 2 +- types/activity.type.ts | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/server/manager/activity.ts b/server/manager/activity.ts index 3ea43e393..d0f41e5be 100644 --- a/server/manager/activity.ts +++ b/server/manager/activity.ts @@ -100,7 +100,7 @@ export const getActivities = async ({ const activities = await subQueryBuilder .orderBy('activity.isPinned', 'DESC') - .addOrderBy('activity.updateDate', 'DESC') + .addOrderBy('activity.publishDate', 'DESC') .limit(limit) .offset(page * limit) .getMany(); diff --git a/src/components/activities/ActivityCard/index.tsx b/src/components/activities/ActivityCard/index.tsx index 1449c0326..76a156262 100644 --- a/src/components/activities/ActivityCard/index.tsx +++ b/src/components/activities/ActivityCard/index.tsx @@ -120,7 +120,7 @@ export const ActivityCard = ({ )}

-

Publié le {toDate(activity.createDate as string)}

+

Publié le {toDate(activity.publishDate as string)}

{userIsPelico ? ( diff --git a/types/activity.type.ts b/types/activity.type.ts index 02e952cad..c71456c48 100644 --- a/types/activity.type.ts +++ b/types/activity.type.ts @@ -39,6 +39,7 @@ export interface Activity { createDate?: Date | string; updateDate?: Date | string; + publishDate?: Date | string; deleteDate?: Date | string; // activity data From 896ef7c49fb23e196e09c76e0fd62dab86e20e1c Mon Sep 17 00:00:00 2001 From: Neo Ryo Date: Thu, 30 May 2024 16:13:26 +0200 Subject: [PATCH 3/3] fix on update --- server/controllers/activity.ts | 8 ++++++-- server/entities/activity.ts | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/server/controllers/activity.ts b/server/controllers/activity.ts index 92aa11dec..630c1b93b 100644 --- a/server/controllers/activity.ts +++ b/server/controllers/activity.ts @@ -291,6 +291,7 @@ const updateActivityValidator = ajv.compile(UPDATE_A_SCHEMA); activityController.put({ path: '/:id', userType: UserType.TEACHER }, async (req: Request, res: Response, next: NextFunction) => { const data = req.body; + if (!updateActivityValidator(data)) { sendInvalidDataError(updateActivityValidator); return; @@ -310,6 +311,7 @@ activityController.put({ path: '/:id', userType: UserType.TEACHER }, async (req: next(); return; } + if (activity.status !== ActivityStatus.PUBLISHED) { if (data.phase) activity.phase = data.phase; if (data.phaseStep) { @@ -334,8 +336,10 @@ activityController.put({ path: '/:id', userType: UserType.TEACHER }, async (req: } } } - - activity.status = data.status ?? activity.status; + if (data.status === 0 && activity.status !== 0) { + activity.status = data.status; + activity.publishDate = new Date(); + } activity.responseActivityId = data.responseActivityId !== undefined ? data.responseActivityId : activity.responseActivityId ?? null; activity.responseType = data.responseType !== undefined ? data.responseType : activity.responseType ?? null; activity.isPinned = data.isPinned !== undefined ? data.isPinned : activity.isPinned; diff --git a/server/entities/activity.ts b/server/entities/activity.ts index fa6318c18..d543aae49 100644 --- a/server/entities/activity.ts +++ b/server/entities/activity.ts @@ -50,7 +50,7 @@ export class Activity implements ActivityInterface { @CreateDateColumn() public createDate: Date; - @CreateDateColumn() + @Column() public publishDate: Date; @UpdateDateColumn()