Skip to content
This repository was archived by the owner on Feb 28, 2026. It is now read-only.
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
30 changes: 30 additions & 0 deletions packages/backend/api/src/albums/albums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
res.json(albums);
return;
} catch (error) {
console.error('Error fetching albums :', error);

Check warning on line 57 in packages/backend/api/src/albums/albums.ts

View workflow job for this annotation

GitHub Actions / check-pr

Unexpected console statement
res.status(500).json({ error: 'Internal Server Error' });
}
});
Expand All @@ -76,7 +76,7 @@
res.json(albums);
return;
} catch (error) {
console.error('Error fetching albums :', error);

Check warning on line 79 in packages/backend/api/src/albums/albums.ts

View workflow job for this annotation

GitHub Actions / check-pr

Unexpected console statement
res.status(500).json({ error: 'Internal Server Error' });
}
});
Expand Down Expand Up @@ -108,7 +108,7 @@
res.json(singlesAlbums);
return;
} catch (error) {
console.error('Error fetching singles :', error);

Check warning on line 111 in packages/backend/api/src/albums/albums.ts

View workflow job for this annotation

GitHub Actions / check-pr

Unexpected console statement
res.status(500).json({ error: 'Internal Server Error' });
}
});
Expand Down Expand Up @@ -175,10 +175,40 @@
)
.execute();

const milestones = await db
.selectFrom('milestones')
.leftJoin('artists_hired', 'artists_hired.milestones_id', 'milestones.id')
.leftJoin(
'label_artists',
'label_artists.artists_hired_id',
'artists_hired.id',
)
.leftJoin('labels', 'labels.id', 'label_artists.label_id')
.select('milestones.value')
.where('labels.users_id', '=', userId)
.executeTakeFirst();

const gain = Number(milestones?.value) / 1000;

const labels = await db
.selectFrom('labels')
.select('labels.notoriety')
.where('labels.users_id', '=', userId)
.executeTakeFirst();

const currentNotoriety = Number(labels?.notoriety);
const newNotoriety = Math.min(Number(currentNotoriety) + Number(gain), 5);

await db
.updateTable('labels')
.set({ notoriety: Number(newNotoriety) })
.where('labels.id', '=', userId)
.execute();

res.status(201).json({ success: true });
return;
} catch (err) {
console.error('Insert failed:', err);

Check warning on line 211 in packages/backend/api/src/albums/albums.ts

View workflow job for this annotation

GitHub Actions / check-pr

Unexpected console statement
res.status(500).json({ error: 'Failed to insert album' });
return;
}
Expand Down
120 changes: 40 additions & 80 deletions packages/backend/api/src/singles/singles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,42 @@ import { db } from '@app/backend-shared';
const singlesRouter = Router();

function getSingles(userId: number) {
return db
.selectFrom('singles')
.leftJoin('artists_hired', 'singles.artists_hired_id', 'artists_hired.id')
.leftJoin('artists', 'artists.id', 'artists_hired.artists_id')
.leftJoin(
'label_artists',
'label_artists.artists_hired_id',
'artists_hired.id',
)
.leftJoin('labels', 'labels.id', 'label_artists.label_id')
.leftJoin('users', 'users.id', 'labels.users_id')
.where('labels.users_id', '=', userId)
.select([
'singles.id',
'singles.artists_hired_id',
'singles.name as name',
'singles.listeners',
'singles.money_earned',
'singles.score',
'artists.firstname as artist_firstname',
'artists.lastname as artist_lastname',
'artists.alias as artist_alias',
]);
return (
db
.selectFrom('singles')
.leftJoin('artists_hired', 'singles.artists_hired_id', 'artists_hired.id')
.leftJoin('artists', 'artists.id', 'artists_hired.artists_id')
.leftJoin(
'label_artists',
'label_artists.artists_hired_id',
'artists_hired.id',
)
.leftJoin('labels', 'labels.id', 'label_artists.label_id')
.leftJoin('users', 'users.id', 'labels.users_id')
// .where('labels.users_id', '=', userId)
.select([
'singles.id',
'singles.artists_hired_id',
'singles.name as name',
'singles.listeners',
'singles.money_earned',
'singles.score',
'artists.firstname as artist_firstname',
'artists.lastname as artist_lastname',
'artists.alias as artist_alias',
])
.where((eb) =>
eb.not(
eb.exists(
eb
.selectFrom('singles_albums')
.select('singles_albums.id')
.whereRef('singles_albums.singles_id', '=', 'singles.id')
.where('labels.users_id', '=', userId),
),
),
)
);
}
export type Single = Awaited<
ReturnType<ReturnType<typeof getSingles>['execute']>
Expand Down Expand Up @@ -75,49 +88,6 @@ singlesRouter.get('/filter', async (req: Request, res) => {
}
});

singlesRouter.get('/:id', async (req: Request, res) => {
const singleId = Number(req.params.id);
const userId = req.userId;
if (userId === undefined) {
res.json({
ok: false,
});
return;
}

try {
const singles = await db
.selectFrom('singles')
.leftJoin('artists_hired', 'singles.artists_hired_id', 'artists_hired.id')
.leftJoin(
'label_artists',
'label_artists.artists_hired_id',
'artists_hired.id',
)
.leftJoin('labels', 'labels.id', 'label_artists.label_id')
.leftJoin('users', 'users.id', 'labels.users_id')
.leftJoin('artists', 'artists.id', 'artists_hired.artists_id')
.where('singles.id', '=', singleId)
.where('labels.users_id', '=', userId)
.select([
'singles.artists_hired_id',
'singles.name',
'singles.listeners',
'singles.money_earned',
'singles.score',
'artists.firstname as artist_firstname',
'artists.lastname as artist_lastname',
'artists.alias as artist_alias',
])
.execute();

res.json(singles);
return;
} catch (error) {
console.error('Error fetching singles:', error);
res.status(500).json({ error: 'Internal Server Error' });
}
});
singlesRouter.post('/', async (req: Request, res) => {
const { artistHiredId, singleName, genreId, price, skills } = req.body;
const userId = req.userId;
Expand Down Expand Up @@ -186,24 +156,19 @@ singlesRouter.post('/', async (req: Request, res) => {
res.status(400).json({ error: 'No milestone found' });
return;
}

if (artistHired.notoriety >= 5) {
res.json({ message: 'max 5' });
return;
}
const currentNotoriety = Number(artistHired.notoriety);
const newNotoriety = Math.min(Number(currentNotoriety) + Number(gain), 5);

await db
.updateTable('artists_hired')
.set((eb) => ({
notoriety: eb('notoriety', '+', Number(gain)),
}))
.set({ notoriety: newNotoriety })
.where('artists_hired.id', '=', artistHiredId)
.execute();

const newMilestone = await db
.selectFrom('milestones')
.select('id')
.where('value', '<=', Number(artistHired.notoriety) * 10)
.where('value', '<=', Number(newNotoriety) * 10)
.orderBy('id', 'desc')
.limit(1)
.executeTakeFirst();
Expand All @@ -213,11 +178,6 @@ singlesRouter.post('/', async (req: Request, res) => {
return;
}

if (newMilestone.id >= 5) {
res.json({ message: 'max 5' });
return;
}

await db
.updateTable('artists_hired')
.set({ milestones_id: newMilestone.id })
Expand Down
6 changes: 3 additions & 3 deletions packages/frontend/web/src/components/modal-singles.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react';

import type { Singles } from '../../../../backend/api/src/singles/singles';
import type { Single } from '../../../../backend/api/src/singles/singles';

export type ModalSinglesProps = {
readonly isOpen: boolean;
Expand All @@ -15,13 +15,13 @@ export function ModalSingles({
artistId,
onSelectSingle,
}: ModalSinglesProps) {
const [singles, setSingles] = useState<Singles[]>([]);
const [singles, setSingles] = useState<Single[]>([]);

useEffect(() => {
const fetchSingles = async () => {
try {
const res = await fetch(`/api/singles`);
const data: Singles[] = await res.json();
const data: Single[] = await res.json();

if (artistId != null) {
const filtered = data.filter(
Expand Down
Loading