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

Feat/badges places and secu role #256

Merged
merged 4 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions src/controllers/admin/badges/generateBadges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ export default [
user.orga.roles[mainCommissionIndex].commission.id,
user.orga.roles[mainCommissionIndex].commission.nameOnBadge,
),
place: user.place,
firstaid: !!user.permissions.includes('firstaid'),
});
}
});
Expand Down Expand Up @@ -177,6 +179,7 @@ export default [
lastName: field.lastname ?? '',
image: field.image ?? '',
commissionName: field.commissionId,
place: field.place,
});
break;
}
Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ export interface Badge {
lastName: string;
image: string;
commissionName: string;
place?: string;
firstaid?: boolean;
}

export interface BadgeField {
Expand All @@ -257,6 +259,7 @@ export interface BadgeField {
lastname?: string;
name?: string;
image?: string;
place?: string;
}

/**********/
Expand Down
23 changes: 22 additions & 1 deletion src/utils/badge.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Porblème de lint, sinon c good

Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import axios, { AxiosResponse } from 'axios';
import { readFileSync } from 'fs';
import PDFkit from 'pdfkit';
import PDFkit, { text } from 'pdfkit';

Check failure on line 3 in src/utils/badge.ts

View workflow job for this annotation

GitHub Actions / lint (18)

'text' is defined but never used
import sharp from 'sharp';
import { Badge } from '../types';
import env from './env';

const getImage = (filename: string) => {
try {
Expand Down Expand Up @@ -129,6 +130,7 @@

// Informations about badge
const image = await fetchImage(badges[index].image);
const firstaid = await fetchImage(`${env.front.website}/uploads/files/badges/first-aid.png`);
// Coordonates
const x = pictureX + col * columnOffset;
const y = pictureY + row * rowOffset;
Expand All @@ -143,6 +145,11 @@

// Background
document.image(await getBadge(badges[index].type), x, y, { width: pictureSize }); // After the image because of... 42

// FirstAid
if (badges[index].firstaid) {
document.image(firstaid, x + 60, y + 216, { width: pictureSize - 120 });
}
}
}

Expand Down Expand Up @@ -205,6 +212,20 @@

// Background
document.image(await getBack(badges[index].type), x, y, { width: pictureSize }); // After the image because of... 42

const color: PDFKit.Mixins.ColorValue = [23, 18, 74];
const textFormat = document.font(fontFamily).fill(color).fontSize(fontSize);

// Offsets
const offsetX = textX + (3 - col) * columnOffset;
const offsetY = textY + row * rowOffset;

// Place
const place = badges[index].place
? `${badges[index].place}`
: `Z${(index + 501).toString().padStart(3, '0')}`;
const placeHeight = textFormat.heightOfString(place);
textFormat.text(place, offsetX - 75, offsetY - 231 - placeHeight / 2);
}
}

Expand Down
Loading