mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
Add sql structure
This commit is contained in:
1 parent
a97d858f99
commit
1959b9c209
3 files changed
+72
-6
No files matched your search
+48
@@ -1,6 +1,7 @@
|
||||
# comment this out if your server has a different table/location for phone_number
|
||||
# or if it already exists in the users table
|
||||
ALTER TABLE `users` ADD COLUMN `phone_number` VARCHAR(20) DEFAULT NULL;
|
||||
ALTER TABLE `users` ADD COLUMN `email` VARCHAR(255) DEFAULT NULL;
|
||||
INSERT INTO `items` (`name`, `label`, `weight`, `rare`, `can_remove`) VALUES ('phone', 'Phone', 1, 0, 1);
|
||||
INSERT INTO `items` (`name`, `label`, `weight`, `rare`, `can_remove`) VALUES ('dphone', 'Destroyed Phone', 1, 0, 1);
|
||||
|
||||
@@ -174,3 +175,50 @@ CREATE TABLE IF NOT EXISTS npwd_phone_gallery (
|
||||
image varchar(255) DEFAULT NULL,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS npwd_emails (
|
||||
id int(11) NOT NULL AUTO_INCREMENT,
|
||||
subject varchar(80) NOT NULL,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS npwd_emails_messages (
|
||||
id int(11) NOT NULL AUTO_INCREMENT,
|
||||
parent_id int(11) DEFAULT NULL,
|
||||
email_id int(11) NOT NULL,
|
||||
sender varchar(255) NOT NULL,
|
||||
sender_identifier varchar(255),
|
||||
send_date int(11) NOT NULL,
|
||||
body TEXT,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS npwd_emails_receivers (
|
||||
id int(12) NOT NULL AUTO_INCREMENT,
|
||||
message_id int(11) NOT NULL,
|
||||
receiver varchar(255) NOT NULL,
|
||||
receiver_identifier varchar(255) NOT NULL,
|
||||
read_at int(11) DEFAULT NULL,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS npwd_emails_phone_actions (
|
||||
id int(11) NOT NULL AUTO_INCREMENT,
|
||||
message_id int(11) NOT NULL,
|
||||
label varchar(255) NOT NULL,
|
||||
close_phone int(1) DEFAULT 0,
|
||||
delete_email int(1) DEFAULT 1,
|
||||
href text NOT NULL,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS npwd_emails_external_actions (
|
||||
id int(11) NOT NULL AUTO_INCREMENT,
|
||||
message_id int(11) NOT NULL,
|
||||
label varchar(255) NOT NULL,
|
||||
close_phone int(1) DEFAULT 0,
|
||||
delete_email int(1) DEFAULT 1,
|
||||
event_name varchar(255) NOT NULL,
|
||||
event_arg text,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
@@ -17,13 +17,13 @@ export interface IEmailMessage {
|
||||
receivers: string[];
|
||||
sender: string;
|
||||
sendDate: number;
|
||||
subject: string;
|
||||
body: string;
|
||||
phoneActions?: Array<IEmailPhoneAction>;
|
||||
externalActions?: Array<IEmailExternalAction>;
|
||||
}
|
||||
|
||||
export interface IEmail {
|
||||
id: number;
|
||||
subject: string;
|
||||
messages: IEmailMessage[];
|
||||
phoneActions?: Array<IEmailPhoneAction>;
|
||||
externalActions?: Array<IEmailExternalAction>;
|
||||
}
|
||||
@@ -5,11 +5,29 @@ import { pool } from './db';
|
||||
|
||||
const emailLogger = mainLogger.child({ module: 'contact' });
|
||||
|
||||
async function fetchInbox(email: string): Promise<any> {
|
||||
async function fetchInbox(identifier: string): Promise<any> {
|
||||
const query = `
|
||||
SELECT * FROM npwd_emails WHERE id = ?
|
||||
SELECT
|
||||
npwd_emails.subject,
|
||||
npwd_emails_messages.parent_id,
|
||||
npwd_emails_messages.email_id,
|
||||
npwd_emails_messages.sender,
|
||||
npwd_emails_messages.sender_identifier,
|
||||
npwd_emails_messages.send_date,
|
||||
npwd_emails_messages.body,
|
||||
npwd_emails_receivers.id,
|
||||
npwd_emails_receivers.receiver,
|
||||
npwd_emails_receivers.receiver_identifier
|
||||
FROM (
|
||||
SELECT id, read_at, message_id FROM npwd_emails_receivers WHERE npwd_emails_receivers.receiver_identifier = ?
|
||||
) as er
|
||||
LEFT OUTER JOIN npwd_emails_messages ON npwd_emails_messages.id = er.message_id
|
||||
LEFT OUTER JOIN npwd_emails_receivers ON npwd_emails_receivers.message_id = npwd_emails_messages.id
|
||||
LEFT OUTER JOIN npwd_emails ON npwd_emails.id = npwd_emails_messages.email_id
|
||||
WHERE npwd_emails_receivers.receiver_identifier = ?
|
||||
ORDER BY npwd_emails_messages.send_date DESC
|
||||
`;
|
||||
const result = await pool.query(query, [email]);
|
||||
const result = await pool.query(query, [identifier]);
|
||||
return result[0];
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user