Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ar(feat) [DPCP-40]: Parse Services. #45

Merged
merged 20 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

# npm run format:fix
npm run format:fix
# npm run build
git add .
# git commit -m "husky(lint)"
1 change: 1 addition & 0 deletions lib/dictionaries/global/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"continue with": "Continue with",
"sign in": "Sign in",
"sign out": "Sign out",
"your email": "Your email",
"i hope you make yourself at home": "I hope you make yourself at home"
},
"CardGrid": {
Expand Down
22 changes: 14 additions & 8 deletions lib/model/decorators/hypnos-public-decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@
import type { ICard } from '@dreampipcom/oneiros';

/* private */
const decorateListing = (listing: Record<string, any>, uMeta: any): ICard => {
const decorateListing = (listing: Record<string, any>, uMeta: any, locale?: string): ICard => {
const decd: ICard = {
id: `${listing.id}`,
className: '',
title: `${listing?.title?.es}`,
title: `${listing?.title[locale || 'en']}`,
description: `${listing?.description[locale || 'en']}`,
where: `${listing?.location?.name}`,
when: `${new Date().toLocaleString()}`,
image: `https://placehold.co/600x400`,
price: `10 KRN`,
latlng: `${listing?.location?.geo}`,
when: `${listing?.scheduledFor}`,
images: listing?.images || [`https://placehold.co/600x400`],
price: `${listing?.value} KRN`,
link: 'https://www.dreampip.com',
badgeLink: 'https://www.dreampip.com',
rating: '3/5',
rating: `${Math.floor(Math.random() * 10)}/10`,
selected: uMeta?.favorites?.includes(listing.id),
} as Record<string, any> as ICard;
// decd.favorite = undefined;
Expand All @@ -25,8 +27,12 @@ const decorateListing = (listing: Record<string, any>, uMeta: any): ICard => {
};

/* public */
export const decorateHypnosPublicListings = async (listings: Record<string, any>[], uMeta: any): Promise<ICard[]> => {
export const decorateHypnosPublicListings = async (
listings: Record<string, any>[],
uMeta: any,
locale?: string,
): Promise<ICard[]> => {
// const uMeta: UserSchema = await getUserMeta({ email: uid });
const decd: ICard[] = listings?.map((card) => decorateListing(card, uMeta));
const decd: ICard[] = listings?.map((card) => decorateListing(card, uMeta, locale));
return decd;
};
6 changes: 3 additions & 3 deletions lib/model/decorators/rm-decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ const decorateCharacter = (character: INCharacter, uMeta: any): ICard => {
title: `${character?.name}`,
where: `${character?.location?.name}`,
when: `${character?.status}`,
image: `${character?.image}`,
price: '299',
images: [`${character?.image}`],
price: '299£',
link: 'https://www.dreampip.com',
badgeLink: 'https://www.dreampip.com',
rating: '3/5',
rating: `${Math.floor(Math.random() * 10)}/10`,
selected: uMeta?.favoritesStrings?.includes(id),
} as Record<string, any> as ICard;

Expand Down
6 changes: 5 additions & 1 deletion lib/model/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ export { DATABASE_STRING, DATABASE_USERS_STRING, DATABASE_ORGS_STRING } from './
export { getCharacters as getRMCharacters } from './services/rickmorty/rm-connector';

export { getPublicListings as getHypnosPublicListings } from './services/hypnos/public/hypnos-public-connector';
export { updateUserFavoriteListings } from './services/hypnos/private/hypnos-private-user-connector';
export {
updateUserFavoriteListings,
getUserHypnosServices,
getUserHypnosAbilities,
} from './services/hypnos/private/hypnos-private-user-connector';
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import { fetchWithTimeout } from '../../../helpers';
// }
// `;

async function fetchREPL({ paramsStr, method, listings }: any) {
async function fetchREPL({ paramsStr, method, listings, action }: any) {
// to-do: might be worth hardcoding the api in case too many middleware requests are billed
try {
const cookieStore = cookies();
const cookieString = cookieStore.toString();
const payload = JSON.stringify({ listings });
const payload = JSON.stringify({ listings, action });
const req = await fetchWithTimeout(`${process.env.API_HOST}/api/v1/user${paramsStr}`, {
method,
headers: {
Expand All @@ -56,3 +56,17 @@ export const updateUserFavoriteListings: ({ paramsStr }: any) => Promise<ICard[]
const response = entries?.data;
return response;
};

export const getUserHypnosServices: ({ paramsStr }: any) => Promise<ICard[]> = async ({ paramsStr = '' }: any) => {
const action = 'get-own-services';
const entries = await fetchREPL({ paramsStr, method: 'POST', action });
const response = entries?.data;
return response;
};

export const getUserHypnosAbilities: ({ paramsStr }: any) => Promise<ICard[]> = async ({ paramsStr = '' }: any) => {
const action = 'get-own-abilities';
const entries = await fetchREPL({ paramsStr, method: 'POST', action });
const response = entries?.data;
return response;
};
6 changes: 5 additions & 1 deletion lib/model/interfaces/services/hypnos/private/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
// index.ts
export { updateUserFavoriteListings } from './hypnos-private-user-connector';
export {
updateUserFavoriteListings,
getUserHypnosServices,
getUserHypnosAbilities,
} from './hypnos-private-user-connector';
16 changes: 14 additions & 2 deletions lib/state/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,22 @@ import { Globals } from '@dreampipcom/oneiros';
import { AuthContext, GlobalContext, RMContext, HypnosPublicContext } from '@state';
import { useLocalStorage } from '@hooks';

export function RootProviders({ children, locale }: { children: React.ReactNode; locale: string }) {
export function RootProviders({
children,
locale,
user,
services,
abilities,
}: {
children: React.ReactNode;
locale: string;
user: any;
services: any;
abilities: any;
}) {
const authContext = useContext<IAuthContext>(AuthContext);
const globalContext = useContext<IGlobalContext>(GlobalContext);
const [authState, setAuthState] = useState<IAuthContext>({ ...authContext });
const [authState, setAuthState] = useState<IAuthContext>({ ...authContext, user, services, abilities });
const [globalState, setGlobalState] = useState<IGlobalContext>({ ...globalContext, locale });
const init = useRef(false);

Expand Down
5 changes: 3 additions & 2 deletions lib/types/contexts.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// contexts.d.ts
// import type { ICard } from '@dreampipcom/oneiros';
import type { UserSchema } from '@types';
import type { Dispatch, SetStateAction } from 'react';

export interface History {
Expand Down Expand Up @@ -31,7 +30,9 @@ export interface IAuthContext extends History {
authd?: boolean;
name?: string;
email?: string;
user?: UserSchema;
user?: any;
services?: any;
abilities?: any;
}

export interface IGlobalContext extends History {
Expand Down
Loading
Loading