Add badges, checkins, and transport endpoints

Introduce gamification and check-in support plus expanded transport/admin APIs. Added DDL for checkins, badges and user_badges. New repositories: badgeRepository, userBadgeRepository, checkinRepository. New routes: admin badge management, admin transport (lines/platforms/stations), public transport endpoints, user checkins and stations endpoints, and user badges on /me. Services updated: adminService (badge CRUD & user assignment), userService (checkins, badge queries), authService (hasAdminRights). Minor package.json name update. These changes implement database, repo, service and route wiring for badges, user_badins and checkin features and additional transport admin routes.
This commit is contained in:
2026-09-23 02:09:39 +02:00
parent e5eccb77db
commit b03f5c91e6
22 changed files with 686 additions and 24 deletions
+21
View File
@@ -0,0 +1,21 @@
CREATE TABLE IF NOT EXISTS `checkins` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`userId` UUID NOT NULL,
`stationId` INT UNSIGNED NOT NULL,
`platformId` INT UNSIGNED NULL COMMENT 'Platform optionnelle pour plus de détail',
`latitude` DECIMAL(10, 8) NOT NULL,
`longitude` DECIMAL(11, 8) NOT NULL,
`distance` FLOAT NOT NULL COMMENT 'Distance en mètres du point de poinçonnage à la plateforme/station',
`checkinAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
INDEX idx_checkins_user (userId),
INDEX idx_checkins_station (stationId),
INDEX idx_checkins_platform (platformId),
INDEX idx_checkins_timestamp (checkinAt),
UNIQUE KEY uq_checkins_user_station_time (userId, stationId, checkinAt),
CONSTRAINT `fk_checkins_userId` FOREIGN KEY (`userId`) REFERENCES `users` (`id`) ON DELETE CASCADE,
CONSTRAINT `fk_checkins_stationId` FOREIGN KEY (`stationId`) REFERENCES `stations` (`id`) ON DELETE CASCADE,
CONSTRAINT `fk_checkins_platformId` FOREIGN KEY (`platformId`) REFERENCES `platforms` (`id`) ON DELETE SET NULL
);
+10
View File
@@ -0,0 +1,10 @@
CREATE TABLE IF NOT EXISTS `badges` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL UNIQUE,
`description` TEXT,
`icon` TEXT,
`condition` VARCHAR(255) NOT NULL COMMENT 'Ex: checkins_count >= 10',
`createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id)
);
+13
View File
@@ -0,0 +1,13 @@
CREATE TABLE IF NOT EXISTS `user_badges` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`userId` UUID NOT NULL,
`badgeId` INT UNSIGNED NOT NULL,
`unlockedAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY uq_user_badges_user_badge (userId, badgeId),
INDEX idx_user_badges_user (userId),
CONSTRAINT `fk_user_badges_userId` FOREIGN KEY (`userId`) REFERENCES `users` (`id`) ON DELETE CASCADE,
CONSTRAINT `fk_user_badges_badgeId` FOREIGN KEY (`badgeId`) REFERENCES `badges` (`id`) ON DELETE CASCADE
);