From 52b9d125f7d3a20510f5f68320fbad44282179ed Mon Sep 17 00:00:00 2001 From: seb Date: Fri, 31 Jul 2026 04:52:14 +0200 Subject: [PATCH] u --- scripts/test-api.js | 15 +++++++++++++++ src/index.js | 4 ++++ src/sql/google_auth.js | 12 ++++++++++++ src/store/google_auth/getByEmail.js | 13 +++++++++++++ src/store/google_auth/getById.js | 13 +++++++++++++ 5 files changed, 57 insertions(+) create mode 100644 src/store/google_auth/getByEmail.js create mode 100644 src/store/google_auth/getById.js diff --git a/scripts/test-api.js b/scripts/test-api.js index 4f620d7..cf6dfee 100644 --- a/scripts/test-api.js +++ b/scripts/test-api.js @@ -97,6 +97,8 @@ const MENU = { label: 'google_auth', items: [ { value: 'google_auth.add', label: 'add', hint: 'email → authId' }, + { value: 'google_auth.getById', label: 'getById', hint: 'id → row' }, + { value: 'google_auth.getByEmail', label: 'getByEmail', hint: 'email → row' }, { value: 'google_auth.list', label: 'list', hint: '→ rows' }, { value: 'google_auth.del', label: 'del', hint: 'id' }, ], @@ -311,6 +313,19 @@ async function runMethod(client, action) { if (email == null) return; return ['authId', await client.google_auth.add(email)]; } + case 'google_auth.getById': { + const id = await askInt('Auth id'); + if (id == null) return; + return ['row', await client.google_auth.getById(Number(id))]; + } + case 'google_auth.getByEmail': { + const email = await askText('Email', { + placeholder: 'user@example.com', + validate: (v) => (!v?.trim() ? 'Required' : undefined), + }); + if (email == null) return; + return ['row', await client.google_auth.getByEmail(email)]; + } case 'google_auth.list': { return ['rows', await client.google_auth.list()]; } diff --git a/src/index.js b/src/index.js index 7a7a8c8..a82c29a 100644 --- a/src/index.js +++ b/src/index.js @@ -15,6 +15,8 @@ import langCreate from './store/lang/create.js'; import langDelete from './store/lang/delete.js'; import langList from './store/lang/list.js'; import googleAuthAdd from './store/google_auth/add.js'; +import googleAuthGetById from './store/google_auth/getById.js'; +import googleAuthGetByEmail from './store/google_auth/getByEmail.js'; import googleAuthList from './store/google_auth/list.js'; import googleAuthDel from './store/google_auth/del.js'; import storePurge from './store/purge.js'; @@ -54,6 +56,8 @@ export default class LibDashStore { this.google_auth = { add: googleAuthAdd(pool), + getById: googleAuthGetById(pool), + getByEmail: googleAuthGetByEmail(pool), list: googleAuthList(pool), del: googleAuthDel(pool), }; diff --git a/src/sql/google_auth.js b/src/sql/google_auth.js index a6027fc..6390396 100644 --- a/src/sql/google_auth.js +++ b/src/sql/google_auth.js @@ -4,6 +4,18 @@ OUTPUT INSERTED.id VALUES (@email) `; +export const GET_BY_ID = ` +SELECT id, email, created_at, selected_company +FROM google_auth +WHERE id = @id +`; + +export const GET_BY_EMAIL = ` +SELECT id, email, created_at, selected_company +FROM google_auth +WHERE email = @email +`; + export const LIST = ` SELECT id, email, created_at, selected_company FROM google_auth diff --git a/src/store/google_auth/getByEmail.js b/src/store/google_auth/getByEmail.js new file mode 100644 index 0000000..3481251 --- /dev/null +++ b/src/store/google_auth/getByEmail.js @@ -0,0 +1,13 @@ +import sql from 'mssql'; +import { GET_BY_EMAIL } from '../../sql/google_auth.js'; + +export default function getByEmail(pool) { + return async (email) => { + const result = await pool + .request() + .input('email', sql.NVarChar(320), email) + .query(GET_BY_EMAIL); + + return result.recordset[0]; + }; +} diff --git a/src/store/google_auth/getById.js b/src/store/google_auth/getById.js new file mode 100644 index 0000000..96c6fac --- /dev/null +++ b/src/store/google_auth/getById.js @@ -0,0 +1,13 @@ +import sql from 'mssql'; +import { GET_BY_ID } from '../../sql/google_auth.js'; + +export default function getById(pool) { + return async (id) => { + const result = await pool + .request() + .input('id', sql.Int, id) + .query(GET_BY_ID); + + return result.recordset[0]; + }; +}