refactor(resources/photo): refactor photos

This commit is contained in:
Christopher committed 2021-04-21 14:34:07 +02:00
1 parent 3470700fc1
commit 10e28b911e
5 files changed
+106 -63

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
import { GalleryPhoto } from '../../../typings/photo';
import { pool } from '../db';
export class _PhotoDB {
async uploadPhoto(identifier: string, image: string): Promise<GalleryPhoto> {
const query = 'INSERT INTO npwd_phone_gallery (identifier, image) VALUES (?, ?)';
const [results] = (await pool.query(query, [identifier, image])) as any;
return { id: results.insertId, image };
}
async getPhotosByIdentifier(identifier: string): Promise<GalleryPhoto[]> {
const query = 'SELECT id, image FROM npwd_phone_gallery WHERE identifier = ? ORDER BY id DESC';
const [results] = await pool.query(query, [identifier]);
return <GalleryPhoto[]>results;
}
async deletePhoto(photo: GalleryPhoto, identifier: string) {
const query = 'DELETE FROM npwd_phone_gallery WHERE image = ? AND identifier = ?';
await pool.query(query, [photo.image, identifier]);
}
}
const PhotoDB = new _PhotoDB();
export default PhotoDB;