Skip to content
This repository was archived by the owner on Feb 28, 2026. It is now read-only.

Commit cf27694

Browse files
committed
albums singles
1 parent 6d3862b commit cf27694

File tree

3 files changed

+40
-70
lines changed

3 files changed

+40
-70
lines changed

packages/backend/api/src/albums/albums.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ albumsRouter.post('/create', async (req: Request, res) => {
188188
.where('labels.users_id', '=', userId)
189189
.executeTakeFirst();
190190

191-
const gain = Number(milestones?.value) / 100;
191+
const gain = Number(milestones?.value) / 1000;
192192

193193
const artistHired = await db
194194
.selectFrom('labels')

packages/backend/api/src/singles/singles.ts

Lines changed: 36 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,42 @@ import { db } from '@app/backend-shared';
55
const singlesRouter = Router();
66

77
function getSingles(userId: number) {
8-
return db
9-
.selectFrom('singles')
10-
.leftJoin('artists_hired', 'singles.artists_hired_id', 'artists_hired.id')
11-
.leftJoin('artists', 'artists.id', 'artists_hired.artists_id')
12-
.leftJoin(
13-
'label_artists',
14-
'label_artists.artists_hired_id',
15-
'artists_hired.id',
16-
)
17-
.leftJoin('labels', 'labels.id', 'label_artists.label_id')
18-
.leftJoin('users', 'users.id', 'labels.users_id')
19-
.where('labels.users_id', '=', userId)
20-
.select([
21-
'singles.id',
22-
'singles.artists_hired_id',
23-
'singles.name as name',
24-
'singles.listeners',
25-
'singles.money_earned',
26-
'singles.score',
27-
'artists.firstname as artist_firstname',
28-
'artists.lastname as artist_lastname',
29-
'artists.alias as artist_alias',
30-
]);
8+
return (
9+
db
10+
.selectFrom('singles')
11+
.leftJoin('artists_hired', 'singles.artists_hired_id', 'artists_hired.id')
12+
.leftJoin('artists', 'artists.id', 'artists_hired.artists_id')
13+
.leftJoin(
14+
'label_artists',
15+
'label_artists.artists_hired_id',
16+
'artists_hired.id',
17+
)
18+
.leftJoin('labels', 'labels.id', 'label_artists.label_id')
19+
.leftJoin('users', 'users.id', 'labels.users_id')
20+
// .where('labels.users_id', '=', userId)
21+
.select([
22+
'singles.id',
23+
'singles.artists_hired_id',
24+
'singles.name as name',
25+
'singles.listeners',
26+
'singles.money_earned',
27+
'singles.score',
28+
'artists.firstname as artist_firstname',
29+
'artists.lastname as artist_lastname',
30+
'artists.alias as artist_alias',
31+
])
32+
.where((eb) =>
33+
eb.not(
34+
eb.exists(
35+
eb
36+
.selectFrom('singles_albums')
37+
.select('singles_albums.id')
38+
.whereRef('singles_albums.singles_id', '=', 'singles.id')
39+
.where('labels.users_id', '=', userId),
40+
),
41+
),
42+
)
43+
);
3144
}
3245
export type Single = Awaited<
3346
ReturnType<ReturnType<typeof getSingles>['execute']>
@@ -75,49 +88,6 @@ singlesRouter.get('/filter', async (req: Request, res) => {
7588
}
7689
});
7790

78-
singlesRouter.get('/:id', async (req: Request, res) => {
79-
const singleId = Number(req.params.id);
80-
const userId = req.userId;
81-
if (userId === undefined) {
82-
res.json({
83-
ok: false,
84-
});
85-
return;
86-
}
87-
88-
try {
89-
const singles = await db
90-
.selectFrom('singles')
91-
.leftJoin('artists_hired', 'singles.artists_hired_id', 'artists_hired.id')
92-
.leftJoin(
93-
'label_artists',
94-
'label_artists.artists_hired_id',
95-
'artists_hired.id',
96-
)
97-
.leftJoin('labels', 'labels.id', 'label_artists.label_id')
98-
.leftJoin('users', 'users.id', 'labels.users_id')
99-
.leftJoin('artists', 'artists.id', 'artists_hired.artists_id')
100-
.where('singles.id', '=', singleId)
101-
.where('labels.users_id', '=', userId)
102-
.select([
103-
'singles.artists_hired_id',
104-
'singles.name',
105-
'singles.listeners',
106-
'singles.money_earned',
107-
'singles.score',
108-
'artists.firstname as artist_firstname',
109-
'artists.lastname as artist_lastname',
110-
'artists.alias as artist_alias',
111-
])
112-
.execute();
113-
114-
res.json(singles);
115-
return;
116-
} catch (error) {
117-
console.error('Error fetching singles:', error);
118-
res.status(500).json({ error: 'Internal Server Error' });
119-
}
120-
});
12191
singlesRouter.post('/', async (req: Request, res) => {
12292
const { artistHiredId, singleName, genreId, price } = req.body;
12393

packages/frontend/web/src/components/modal-singles.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect, useState } from 'react';
22

3-
import type { Singles } from '../../../../backend/api/src/singles/singles';
3+
import type { Single } from '../../../../backend/api/src/singles/singles';
44

55
export type ModalSinglesProps = {
66
readonly isOpen: boolean;
@@ -15,13 +15,13 @@ export function ModalSingles({
1515
artistId,
1616
onSelectSingle,
1717
}: ModalSinglesProps) {
18-
const [singles, setSingles] = useState<Singles[]>([]);
18+
const [singles, setSingles] = useState<Single[]>([]);
1919

2020
useEffect(() => {
2121
const fetchSingles = async () => {
2222
try {
2323
const res = await fetch(`/api/singles`);
24-
const data: Singles[] = await res.json();
24+
const data: Single[] = await res.json();
2525

2626
if (artistId != null) {
2727
const filtered = data.filter(

0 commit comments

Comments
 (0)