1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-25 23:09:22 +00:00

Delete user movies

This commit is contained in:
Pierre HUBERT 2020-03-27 13:57:36 +01:00
parent 77bb8a6ae1
commit 50e2277a30
3 changed files with 39 additions and 0 deletions

View File

@ -32,4 +32,8 @@ export class Movie implements MovieBuilder {
get url() : string { get url() : string {
return pathUserData(this.uri); return pathUserData(this.uri);
} }
get sysPath() : string {
return pathUserData(this.uri, true);
}
} }

View File

@ -456,6 +456,9 @@ export class AccountHelper {
// Delete all the likes created by the user // Delete all the likes created by the user
await LikesHelper.DeleteAllUser(userID); await LikesHelper.DeleteAllUser(userID);
// Delete all user movies
await MoviesHelper.DeleteAllUser(userID);
*/ */
// TODO : continue work // TODO : continue work

View File

@ -1,5 +1,7 @@
import { Movie } from "../entities/Movie"; import { Movie } from "../entities/Movie";
import { DatabaseHelper } from "./DatabaseHelper"; import { DatabaseHelper } from "./DatabaseHelper";
import { PostsHelper } from "./PostsHelper";
import { existsSync, unlinkSync } from "fs";
/** /**
* Legacy movies helper * 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 * Turn a database entry into a movie object
* *