Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ft vil 460 #932

Merged
merged 3 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions server/controllers/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions server/entities/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export class Activity implements ActivityInterface<AnyData> {
@CreateDateColumn()
public createDate: Date;

@Column()
public publishDate: Date;

@UpdateDateColumn()
public updateDate: Date;

Expand Down
2 changes: 1 addition & 1 deletion server/manager/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
20 changes: 20 additions & 0 deletions server/migrations/1717055850587-publishedAtActivityField.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { MigrationInterface, QueryRunner } from 'typeorm';

export class PublishedAtActivityField1717055850587 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
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<void> {
const activityTable = await queryRunner.getTable('activity');
if (activityTable?.columns.find((col) => col.name === 'publishDate')) {
await queryRunner.query(`ALTER TABLE activity
DROP COLUMN publishDate`);
}
}
}
2 changes: 1 addition & 1 deletion src/components/activities/ActivityCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const ActivityCard = ({
)}
</p>
<div style={{ display: 'flex', alignItems: 'center' }}>
<p className="text text--small">Publié le {toDate(activity.createDate as string)} </p>
<p className="text text--small">Publié le {toDate(activity.publishDate as string)} </p>
{userIsPelico ? (
<Link href={`/pelico-profil`}>
<PelicoNeutre style={{ marginLeft: '0.6rem', height: '16px', width: 'auto', cursor: 'pointer' }} />
Expand Down
18 changes: 14 additions & 4 deletions src/components/admin/NewAdminNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
1 change: 1 addition & 0 deletions types/activity.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface Activity<T extends AnyData = AnyData> {

createDate?: Date | string;
updateDate?: Date | string;
publishDate?: Date | string;
deleteDate?: Date | string;

// activity data
Expand Down
Loading