mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-05 06:28:51 +00:00
refactor(resources/photo): refactor photos
This commit is contained in:
1 parent
3470700fc1
commit
10e28b911e
5 files changed
+106
-63
No files matched your search
@@ -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;
|
||||
Reference in new issue
Block a user