Skip to content
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
10 changes: 8 additions & 2 deletions src/routes/admin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,20 @@ adminRouter.post('/accept', async(req,res)=>{
const { adminEmail, userEmail } = req.body;
try {
const admin = await db.user.findOne({where: {email: adminEmail}});
if(admin.rol=== 'admin') {
if (admin.rol === 'admin') {
const user = await db.user.findOne({where: {email: userEmail}});
if(user.rol=== 'artist'){
if (user.rol === 'artist') {
return res.send({message: 'User is already an artist'});
}
user.rol = 'artist';
user.requested_artist = false;
await user.save();
await db.artist.create({
name: user.name,
image_small: user.image_avatar,
image_medium: user.image_avatar,
image_large: user.image_avatar,
})
return res.send({message: 'User accepted'});
}
return res.send({message: 'You are not an admin'});
Expand Down
59 changes: 59 additions & 0 deletions src/routes/artist/album.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import {Router} from "express";
import db from "../../models/db";
import {artistRouter} from "../search";

export const artistAlbumRouter = Router();

artistAlbumRouter.post('/create', async (req, res) => {
const { userEmail, albumName, albumReleaseDate, image_small, image_medium, image_big, genreId } = req.body;
try {
const user = await db.user.findOne({where: {email: userEmail}});
const artist = await db.artist.findOne({where: {userId: user.id}});
const genre = await db.genre.findOne({where: {id: genreId}});
const album = await db.album.create({
name: albumName,
release_date: albumReleaseDate,
image_small: image_small,
image_medium: image_medium,
image_big: image_big,
})
await artist.addAlbum(album);
await album.setGenre(genre);
return res.send({message: 'Album created'});
} catch (e:any) {
return res.send({message: e.message});
}
})

artistAlbumRouter.post('/delete', async (req, res) => {
const { albumId, email } = req.body;
try {
const user = await db.user.findOne({where: {email: email}});
const album = await db.album.findOne({where: {id: albumId}});
const artist = await db.artist.findOne({where: {userId: user.id}});
await artist.removeAlbum(album);
await album.destroy();
return res.send({message: 'Album deleted'});
} catch (e:any) {
return res.send({message: e.message});
}
})

artistAlbumRouter.post('/update', async (req, res) => {
const {email, albumId, albumName, albumReleaseDate, image_small, image_medium, image_big, genreId} = req.body;
try {
const user = await db.user.findOne({where: {email: email}});
const album = await db.album.findOne({where: {id: albumId}});
const genre = await db.genre.findOne({where: {id: genreId}});
await album.update({
name: albumName,
release_date: albumReleaseDate,
image_small: image_small,
image_medium: image_medium,
image_big: image_big,
})
return res.send({message: 'Album updated'});
} catch (e:any) {
return res.send({message: e.message});
}
})
3 changes: 3 additions & 0 deletions src/routes/artist/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './album';
export * from './song';
export * from './profile';
22 changes: 22 additions & 0 deletions src/routes/artist/profile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {Router} from "express";
import db from "../../models/db";

export const artistProfileRouter = Router();

artistProfileRouter.post('/update', async (req, res) => {
const {email, name, description, image_small, image_medium, image_big} = req.body;
try {
const user = await db.user.findOne({where: {email: email}});
const artist = await db.artist.findOne({where: {userId: user.id}});
await artist.update({
name: name,
// description: description,
image_small: image_small,
image_medium: image_medium,
image_big: image_big,
})
return res.send({message: 'Artist updated'});
} catch (e:any) {
return res.send({message: e.message});
}
})
57 changes: 57 additions & 0 deletions src/routes/artist/song.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {Router} from "express";
import db from "../../models/db";

export const artistSongRouter = Router();

artistSongRouter.post('/create', async (req, res) => {
const { userEmail, songName, image_small, image_medium, image_big, duration, preview } = req.body;
try {
const user = await db.user.findOne({where: {email: userEmail}});
const artist = await db.artist.findOne({where: {userId: user.id}});
const song = await db.song.create({
name: songName,
preview: preview,
image_small: image_small,
image_medium: image_medium,
image_big: image_big,
duration: duration,
})
await artist.addSong(song);
return res.send({message: 'Song created'});
} catch (e:any) {
return res.send({message: e.message});
}
})


artistSongRouter.post('/delete', async (req, res) => {
const { songId, email } = req.body;
try {
const user = await db.user.findOne({where: {email: email}});
const song = await db.song.findOne({where: {id: songId}});
const artist = await db.artist.findOne({where: {userId: user.id}});
await artist.removeSong(song);
await song.destroy();
return res.send({message: 'Song deleted'});
} catch (e:any) {
return res.send({message: e.message});
}
})

artistSongRouter.post('/update', async (req, res) => {
const {email, songId, songName, image_small, image_medium, image_big, duration} = req.body;
try {
const user = await db.user.findOne({where: {email: email}});
const song = await db.song.findOne({where: {id: songId}});
await song.update({
name: songName,
image_small: image_small,
image_medium: image_medium,
image_big: image_big,
duration: duration,
})
return res.send({message: 'Song updated'});
} catch (e:any) {
return res.send({message: e.message});
}
})
6 changes: 5 additions & 1 deletion src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import chargeJson from "./charge/chargeJson";
import charge from "./charge/charge";
import chargeTables from "./charge/chargeTables";
import {adminRouter} from "./admin";
import {artistSongRouter, artistAlbumRouter, artistProfileRouter} from "./artist";

export const routes = Router();

Expand All @@ -32,4 +33,7 @@ routes.use('/update', updateRouter)
routes.use('/admin', adminRouter)
routes.use('/requestArtistStatus', artistRequestRouter)
routes.use('/deactivate', deactivateRouter)
routes.use('/info', infoRouter)
routes.use('/info', infoRouter)
routes.use('/artistpanel/album', artistAlbumRouter)
routes.use('/artistpanel/song', artistSongRouter)
routes.use('/artistpanel/profile', artistProfileRouter)