mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 05:19:22 +00:00
Delete user movies
This commit is contained in:
parent
77bb8a6ae1
commit
50e2277a30
@ -32,4 +32,8 @@ export class Movie implements MovieBuilder {
|
||||
get url() : string {
|
||||
return pathUserData(this.uri);
|
||||
}
|
||||
|
||||
get sysPath() : string {
|
||||
return pathUserData(this.uri, true);
|
||||
}
|
||||
}
|
@ -456,6 +456,9 @@ export class AccountHelper {
|
||||
|
||||
// Delete all the likes created by the user
|
||||
await LikesHelper.DeleteAllUser(userID);
|
||||
|
||||
// Delete all user movies
|
||||
await MoviesHelper.DeleteAllUser(userID);
|
||||
*/
|
||||
|
||||
// TODO : continue work
|
||||
|
@ -1,5 +1,7 @@
|
||||
import { Movie } from "../entities/Movie";
|
||||
import { DatabaseHelper } from "./DatabaseHelper";
|
||||
import { PostsHelper } from "./PostsHelper";
|
||||
import { existsSync, unlinkSync } from "fs";
|
||||
|
||||
/**
|
||||
* Legacy movies helper
|
||||
@ -59,6 +61,36 @@ export class MoviesHelper {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a movie created by the user
|
||||
*
|
||||
* @param movie The movie to delete
|
||||
*/
|
||||
public static async Delete(movie: Movie) {
|
||||
|
||||
// Delete all related posts
|
||||
await PostsHelper.DeleteAllWithMovie(movie);
|
||||
|
||||
// Delete associated file
|
||||
if(existsSync(movie.sysPath))
|
||||
unlinkSync(movie.sysPath)
|
||||
|
||||
// Remove movie from database
|
||||
await DatabaseHelper.DeleteRows(MOVIES_TABLE, {
|
||||
ID: movie.id
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all the movies of a given user
|
||||
*
|
||||
* @param userID The ID of the target user
|
||||
*/
|
||||
public static async DeleteAllUser(userID: number) {
|
||||
for(const m of await this.GetListUser(userID))
|
||||
await this.Delete(m);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a database entry into a movie object
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user