update screener page
This commit is contained in:
parent
e07c98d03a
commit
9589d7262c
@ -4,12 +4,6 @@ import { loginUserSchema, registerUserSchema } from "$lib/schemas";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
export const load = async ({ locals}) => {
|
|
||||||
|
|
||||||
if (!locals.pb.authStore.isValid) {
|
|
||||||
redirect(303, '/stock-screener/demo');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
export const actions = {
|
export const actions = {
|
||||||
@ -91,7 +85,7 @@ export const actions = {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
oauth2: async ( { url, locals, request, cookies }) => {
|
oauth2: async ( { url, locals, request, cookies }) => {
|
||||||
const authMethods = await locals?.pb?.collection('users')?.listAuthMethods();
|
const authMethods = await locals?.pb?.collection('users')?.listAuthMethods();
|
||||||
|
|
||||||
const data = await request?.formData();
|
const data = await request?.formData();
|
||||||
@ -137,10 +131,10 @@ export const actions = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
redirect(302,authProviderRedirect);
|
redirect(302,authProviderRedirect);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -17,17 +17,36 @@ const ensureAllEmaParameters = (params) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const load = async ({ parent, params }) => {
|
export const load = async ({ parent, params }) => {
|
||||||
const { apiURL, apiKey, fastifyURL } = await parent();
|
const { apiURL, apiKey, fastifyURL, user } = await parent();
|
||||||
|
|
||||||
const getStrategyId = async () => {
|
const getStrategyId = async () => {
|
||||||
return params.strategyId;
|
return params.strategyId;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getStrategy = async () => {
|
const getAllStrategies = async () => {
|
||||||
|
const postData = { userId: user?.id };
|
||||||
|
const response = await fetch(fastifyURL + "/all-strategies", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(postData),
|
||||||
|
});
|
||||||
|
|
||||||
|
const output = (await response.json())?.items;
|
||||||
|
|
||||||
|
output?.sort((a, b) => new Date(b?.updated) - new Date(a?.updated));
|
||||||
|
|
||||||
|
//console.log(output);
|
||||||
|
|
||||||
|
return output;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getStrategy = async (strategyId) => {
|
||||||
let output;
|
let output;
|
||||||
|
|
||||||
// make the POST request to the endpoint
|
// make the POST request to the endpoint
|
||||||
const postData = { strategyId: params.strategyId };
|
const postData = { strategyId: strategyId };
|
||||||
const response = await fetch(fastifyURL + "/get-strategy", {
|
const response = await fetch(fastifyURL + "/get-strategy", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
@ -43,7 +62,9 @@ export const load = async ({ parent, params }) => {
|
|||||||
|
|
||||||
const getStockScreenerData = async () => {
|
const getStockScreenerData = async () => {
|
||||||
let output;
|
let output;
|
||||||
const strategy = await getStrategy();
|
const strategyList = await getAllStrategies();
|
||||||
|
|
||||||
|
const strategy = await getStrategy(strategyList?.at(0)?.id);
|
||||||
let getRuleOfList = strategy?.rules?.map((item) => item?.name) || [];
|
let getRuleOfList = strategy?.rules?.map((item) => item?.name) || [];
|
||||||
|
|
||||||
// Ensure all required EMA parameters are included
|
// Ensure all required EMA parameters are included
|
||||||
@ -81,5 +102,6 @@ export const load = async ({ parent, params }) => {
|
|||||||
getStockScreenerData: await getStockScreenerData(),
|
getStockScreenerData: await getStockScreenerData(),
|
||||||
getStrategy: await getStrategy(),
|
getStrategy: await getStrategy(),
|
||||||
getStrategyId: await getStrategyId(),
|
getStrategyId: await getStrategyId(),
|
||||||
|
getAllStrategies: await getAllStrategies(),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -1,140 +0,0 @@
|
|||||||
import { error, fail, redirect } from "@sveltejs/kit";
|
|
||||||
import { validateData } from "$lib/utils";
|
|
||||||
import { loginUserSchema, registerUserSchema } from "$lib/schemas";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export const actions = {
|
|
||||||
|
|
||||||
|
|
||||||
login: async ({ request, locals }) => {
|
|
||||||
const { formData, errors } = await validateData(
|
|
||||||
await request.formData(),
|
|
||||||
loginUserSchema,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (errors) {
|
|
||||||
return fail(400, {
|
|
||||||
data: formData,
|
|
||||||
errors: errors.fieldErrors,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await locals.pb
|
|
||||||
.collection("users")
|
|
||||||
.authWithPassword(formData.email, formData.password);
|
|
||||||
|
|
||||||
/*
|
|
||||||
if (!locals.pb?.authStore?.model?.verified) {
|
|
||||||
locals.pb.authStore.clear();
|
|
||||||
return {
|
|
||||||
notVerified: true,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
console.log("Error: ", err);
|
|
||||||
error(err.status, err.message);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
redirect(303, '/');
|
|
||||||
},
|
|
||||||
|
|
||||||
register: async ({ locals, request }) => {
|
|
||||||
const { formData, errors } = await validateData(await request.formData(), registerUserSchema);
|
|
||||||
|
|
||||||
if (errors) {
|
|
||||||
return fail(400, {
|
|
||||||
data: formData,
|
|
||||||
errors: errors.fieldErrors
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
|
||||||
let newUser = await locals.pb.collection('users').create(formData);
|
|
||||||
await locals.pb?.collection('users').update(
|
|
||||||
newUser?.id, {
|
|
||||||
'freeTrial' : true,
|
|
||||||
'tier': 'Pro', //Give new users a free trial for the Pro Subscription
|
|
||||||
});
|
|
||||||
await locals.pb.collection('users').requestVerification(formData.email);
|
|
||||||
} catch (err) {
|
|
||||||
console.log('Error: ', err);
|
|
||||||
error(err.status, err.message);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await locals.pb
|
|
||||||
.collection("users")
|
|
||||||
.authWithPassword(formData.email, formData.password);
|
|
||||||
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
console.log("Error: ", err);
|
|
||||||
error(err.status, err.message);
|
|
||||||
}
|
|
||||||
|
|
||||||
redirect(303, "/");
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
oauth2: async ( { url, locals, request, cookies }) => {
|
|
||||||
const authMethods = await locals?.pb?.collection('users')?.listAuthMethods();
|
|
||||||
|
|
||||||
const data = await request?.formData();
|
|
||||||
const providerSelected = data?.get('provider');
|
|
||||||
|
|
||||||
if (!authMethods) {
|
|
||||||
return {
|
|
||||||
authProviderRedirect: '',
|
|
||||||
authProviderState: ''
|
|
||||||
};
|
|
||||||
}
|
|
||||||
const redirectURL = `${url.origin}/oauth`;
|
|
||||||
|
|
||||||
const targetItem = authMethods.authProviders?.findIndex(item => item?.name === providerSelected );
|
|
||||||
//console.log("==================")
|
|
||||||
//console.log(authMethods.authProviders)
|
|
||||||
//console.log('target item is: ', targetItem)
|
|
||||||
|
|
||||||
const provider = authMethods.authProviders[targetItem];
|
|
||||||
const authProviderRedirect = `${provider.authUrl}${redirectURL}`;
|
|
||||||
const state = provider.state;
|
|
||||||
const verifier = provider.codeVerifier;
|
|
||||||
|
|
||||||
cookies.set('state', state, {httpOnly: true,
|
|
||||||
sameSite: 'lax',
|
|
||||||
secure: true,
|
|
||||||
path: '/',
|
|
||||||
maxAge: 60*60
|
|
||||||
});
|
|
||||||
|
|
||||||
cookies.set('verifier', verifier, {httpOnly: true,
|
|
||||||
sameSite: 'lax',
|
|
||||||
secure: true,
|
|
||||||
path: '/',
|
|
||||||
maxAge: 60*60
|
|
||||||
});
|
|
||||||
|
|
||||||
cookies.set('provider', providerSelected, {httpOnly: true,
|
|
||||||
sameSite: 'lax',
|
|
||||||
secure: true,
|
|
||||||
path: '/',
|
|
||||||
maxAge: 60*60
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
redirect(302,authProviderRedirect);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user