Skip to content
Snippets Groups Projects
Commit f67fc592 authored by Razzan Yoni's avatar Razzan Yoni
Browse files

feat : add ftp functionality

parent 9fcfbecd
1 merge request!2Dev
......@@ -2,6 +2,7 @@ import { NextFunction, Request, Response } from "express";
import * as PremiumSongService from "../services/premium-song-services"
import { generateResponse } from "../utils/response";
import { StatusCodes } from "http-status-codes";
import {ErrorType, StandardError} from "../errors/standard-error";
const addNewSong = async (
req: Request,
......@@ -11,6 +12,15 @@ const addNewSong = async (
try {
const data = req.body;
const premiumAlbumId = Number(req.params.premiumAlbumId);
if (!req.file) {
throw new StandardError(ErrorType.FILE_NOT_VALID);
}
data.audioFilename = req.file.filename;
data.songNumber = Number(data.songNumber);
if (data.discNumber) {
data.discNumber = Number(data.discNumber);
}
data.duration = Number(data.duration);
const responseData = await PremiumSongService.addNewSong(data, premiumAlbumId);
generateResponse(res, StatusCodes.OK, responseData);
} catch (err) {
......@@ -41,6 +51,23 @@ const updatePremiumSong = async (
const data = req.body;
const premiumAlbumId = Number(req.params.premiumAlbumId);
const premiumSongId = Number(req.params.premiumSongId);
if (data.songNumber) {
data.songNumber = Number(data.songNumber);
}
if (data.discNumber) {
data.discNumber = Number(data.discNumber);
}
if (data.duration) {
data.duration = Number(data.duration);
}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (req.files && req.files[0]) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
data.audioFilename = req.files[0].filename;
}
const responseData = await PremiumSongService.updatePremiumSong(data, premiumAlbumId, premiumSongId);
generateResponse(res, StatusCodes.OK, responseData);
} catch (err) {
......
......@@ -2,12 +2,14 @@ import express, { Router } from "express";
import * as PremiumSongController from "../controllers/premium-song-controller";
import { handleStandardError } from "../middlewares/handle-standard-error";
import { verifyToken } from "../middlewares/verify-token";
import {uploadSong} from "../utils/file-processing";
const premiumSongRouter: Router = express.Router();
premiumSongRouter.post(
"/api/premium-album/:premiumAlbumId",
verifyToken,
uploadSong.single("songFile"),
PremiumSongController.addNewSong,
handleStandardError,
);
......@@ -22,6 +24,7 @@ premiumSongRouter.get(
premiumSongRouter.patch(
"/api/premium-album/:premiumAlbumId/:premiumSongId",
verifyToken,
uploadSong.any(),
PremiumSongController.updatePremiumSong,
handleStandardError,
);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment