Migrated the media.ts controller
This commit is contained in:
parent
f270bd9b76
commit
41ca7ec669
@ -1,4 +1,4 @@
|
|||||||
import {Media} from "../models/Media";
|
import {IMedia, Media} from "../models/Media";
|
||||||
import {Response} from "express";
|
import {Response} from "express";
|
||||||
import {bucket} from "./bucket";
|
import {bucket} from "./bucket";
|
||||||
|
|
||||||
@ -15,13 +15,13 @@ export const createMedia = (clientId: number, assetName: string, assetEnding: st
|
|||||||
* Gets a media object from an id
|
* Gets a media object from an id
|
||||||
* @param assetId The id of the asset to search
|
* @param assetId The id of the asset to search
|
||||||
*/
|
*/
|
||||||
export const getMediaById = (assetId: string) => Media.findOne({assetId}, {_id: 0, __v: 0});
|
export const getMediaById = (assetId: string) => Media.findOne({where: {assetId}});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a complete media object by the asset id
|
* Gets a complete media object by the asset id
|
||||||
* @param assetId The id of the asset to search
|
* @param assetId The id of the asset to search
|
||||||
*/
|
*/
|
||||||
export const getMediaObject = (assetId: string) => Media.findOne({assetId});
|
export const getMediaObject = (assetId: string) => Media.findOne({where: {assetId}}) as Promise<IMedia>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pipes the provided asset into an express response
|
* Pipes the provided asset into an express response
|
||||||
@ -35,6 +35,6 @@ export const pipeMedia = (assetId: string, res: Response) => bucket.file(assetId
|
|||||||
* @param assetId The id of the asset to delete
|
* @param assetId The id of the asset to delete
|
||||||
*/
|
*/
|
||||||
export const deleteMedia = async (assetId: string) => {
|
export const deleteMedia = async (assetId: string) => {
|
||||||
await Media.deleteOne({assetId});
|
await Media.destroy({where: {assetId}});
|
||||||
await bucket.file(assetId).delete();
|
await bucket.file(assetId).delete();
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user