From 430219a6d8ef3980505cb3fd6c93f9ba765cece0 Mon Sep 17 00:00:00 2001 From: valeriagrazzini Date: Fri, 23 Sep 2022 17:21:06 +0200 Subject: [PATCH 1/2] created new endpoint to get active accounts email and info --- src/controllers/account/account.router.ts | 3 +++ src/controllers/account/list.action.ts | 17 +++++++++++++++++ src/services/AccountService.ts | 4 ++++ 3 files changed, 24 insertions(+) create mode 100644 src/controllers/account/list.action.ts diff --git a/src/controllers/account/account.router.ts b/src/controllers/account/account.router.ts index 75e6a4b..61af2bc 100644 --- a/src/controllers/account/account.router.ts +++ b/src/controllers/account/account.router.ts @@ -17,11 +17,13 @@ import { getSpotifyUserFollow, getSpotifyPlaylistFollow } from './spotify/get.fo import { getSpotifyTrackPlaying, getSpotifyTrackRecent, getSpotifyTrackSaved } from './spotify/get.track.action'; import { getSpotify } from './spotify/get.action'; import { createLoginValidation, postLogin } from './login/post.controller'; +import { getActiveAccountsEmail } from './list.action'; const router = express.Router(); router.use(validateJwt); router.post('/', guard.check(['account:read', 'account:write']), validate(validations.postAccount), postAccount); +router.get('/emails/', guard.check(['account:read']), getActiveAccountsEmail); router.get('/:id', guard.check(['account:read']), getAccount); router.get('/:sub/twitter', guard.check(['account:read']), getTwitter); @@ -41,6 +43,7 @@ router.get('/:sub/spotify/track_recent/:item', guard.check(['account:read']), ge router.get('/:sub/spotify/track_saved/:item', guard.check(['account:read']), getSpotifyTrackSaved); router.get('/address/:address', guard.check(['account:read']), validate([]), getAccountByAddress); + router.get('/email/:email', guard.check(['account:read']), validate([]), getAccountByEmail); router.patch('/:id', guard.check(['account:read', 'account:write']), patchAccount); router.delete('/:id', guard.check(['account:write']), deleteAccount); diff --git a/src/controllers/account/list.action.ts b/src/controllers/account/list.action.ts new file mode 100644 index 0000000..5a04160 --- /dev/null +++ b/src/controllers/account/list.action.ts @@ -0,0 +1,17 @@ +import { Request, Response } from 'express'; +import { AccountService } from '../../services/AccountService'; + +export const getActiveAccountsEmail = async (req: Request, res: Response) => { + const accounts = await AccountService.getActiveAccountsEmail(); + console.log('accounts', accounts); + const result = accounts.map((account) => { + return { + id: String(account._id), + firstName: account.firstName, + email: account.email, + createdAt: account.createdAt, + }; + }); + + res.send(result); +}; diff --git a/src/services/AccountService.ts b/src/services/AccountService.ts index 7b7f955..ba923cb 100644 --- a/src/services/AccountService.ts +++ b/src/services/AccountService.ts @@ -344,4 +344,8 @@ export class AccountService { return { error }; } } + + static getActiveAccountsEmail() { + return Account.find({ active: true, email: { $ne: null } }, { _id: 1, firstName: 1, email: 1, createdAt: 1 }); + } } From 41f3eabe5a6b9a0acb3c988d52c6c6e8113a42dc Mon Sep 17 00:00:00 2001 From: valeriagrazzini Date: Wed, 5 Oct 2022 20:27:28 +0200 Subject: [PATCH 2/2] added active as output parameter --- src/controllers/account/get.action.ts | 1 + src/controllers/account/list.action.ts | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/account/get.action.ts b/src/controllers/account/get.action.ts index 413de36..157cc6f 100644 --- a/src/controllers/account/get.action.ts +++ b/src/controllers/account/get.action.ts @@ -16,6 +16,7 @@ function formatAccountRes(account: any) { company: account.company, plan: account.plan, email: account.email, + active: account.active, googleAccess: account.googleAccessToken && account.googleAccessTokenExpires > Date.now(), twitterAccess: account.twitterAccessToken && account.twitterAccessTokenExpires > Date.now(), spotifyAccess: account.spotifyAccessToken && account.spotifyAccessTokenExpires > Date.now(), diff --git a/src/controllers/account/list.action.ts b/src/controllers/account/list.action.ts index 5a04160..9131bbf 100644 --- a/src/controllers/account/list.action.ts +++ b/src/controllers/account/list.action.ts @@ -3,7 +3,6 @@ import { AccountService } from '../../services/AccountService'; export const getActiveAccountsEmail = async (req: Request, res: Response) => { const accounts = await AccountService.getActiveAccountsEmail(); - console.log('accounts', accounts); const result = accounts.map((account) => { return { id: String(account._id),