Skip to content

Commit

Permalink
feat: broky
Browse files Browse the repository at this point in the history
  • Loading branch information
Stormix committed Sep 17, 2023
1 parent dceb0b9 commit bfeceaa
Show file tree
Hide file tree
Showing 37 changed files with 5,196 additions and 514 deletions.
16 changes: 16 additions & 0 deletions apps/api/app/Controllers/Http/AuthController.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
import { Limiter } from '@adonisjs/limiter/build/services/index'
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
import { rules, schema } from '@ioc:Adonis/Core/Validator'
import { LoginDTO } from 'shared/dist/dto/user'
import User from '../../Models/User'

export default class AuthController {
public async authenticate({ request, response, auth }: HttpContextContract) {
try {
const { fingerprint } = request.only(['fingerprint'])
const user = await User.firstOrCreate({ fingerprint })
const token = await auth.use('api').generate(user)

return response.json({ token } as LoginDTO)
} catch (error) {
console.log(error)
return response.badRequest({
error: { message: 'Unable to authenticate' },
})
}
}

public async register({ request, response, auth }: HttpContextContract) {
const throttleKey = `register_${request.ip()}`
const limiter = Limiter.use({
Expand Down
6 changes: 5 additions & 1 deletion apps/api/app/Models/CarpoolingAd.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { BaseModel, column } from '@ioc:Adonis/Lucid/Orm'
import { BaseModel, belongsTo, BelongsTo, column } from '@ioc:Adonis/Lucid/Orm'
import { DateTime } from 'luxon'
import { CarpoolingStatus } from '../../contracts/status'
import User from './User'

export default class CarpoolingAd extends BaseModel {
@column({ isPrimary: true })
public id: number

@belongsTo(() => User)
public user: BelongsTo<typeof User>

@column()
public type: 'offer' | 'request'

Expand Down
15 changes: 13 additions & 2 deletions apps/api/app/Models/HelpRequest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { BaseModel, column, manyToMany, ManyToMany } from '@ioc:Adonis/Lucid/Orm'
import {
BaseModel,
BelongsTo,
belongsTo,
column,
manyToMany,
ManyToMany
} from '@ioc:Adonis/Lucid/Orm'
import { DateTime } from 'luxon'
import { HelpRequestStatus } from '../../contracts/status'
import Type from './Type'
import User from './User'

export default class HelpRequest extends BaseModel {
@column({ isPrimary: true })
Expand All @@ -12,10 +20,13 @@ export default class HelpRequest extends BaseModel {
pivotForeignKey: 'help_request_id',
relatedKey: 'id',
pivotRelatedForeignKey: 'type_id',
pivotTable: 'help_request_types',
pivotTable: 'help_request_types'
})
public types: ManyToMany<typeof Type>

@belongsTo(() => User)
public user: BelongsTo<typeof User>

@column()
public longitude: number

Expand Down
15 changes: 13 additions & 2 deletions apps/api/app/Models/Offer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { BaseModel, column, ManyToMany, manyToMany } from '@ioc:Adonis/Lucid/Orm'
import {
BaseModel,
BelongsTo,
belongsTo,
column,
ManyToMany,
manyToMany
} from '@ioc:Adonis/Lucid/Orm'
import { DateTime } from 'luxon'
import { OfferStatus } from '../../contracts/status'
import Type from './Type'
import User from './User'

export default class Offer extends BaseModel {
@column({ isPrimary: true })
Expand All @@ -12,10 +20,13 @@ export default class Offer extends BaseModel {
pivotForeignKey: 'offer_id',
relatedKey: 'id',
pivotRelatedForeignKey: 'type_id',
pivotTable: 'offer_types',
pivotTable: 'offer_types'
})
public types: ManyToMany<typeof Type>

@belongsTo(() => User)
public user: BelongsTo<typeof User>

@column()
public longitude: number

Expand Down
14 changes: 13 additions & 1 deletion apps/api/app/Models/User.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { BaseModel, column } from '@ioc:Adonis/Lucid/Orm'
import { BaseModel, column, HasMany, hasMany } from '@ioc:Adonis/Lucid/Orm'
import { DateTime } from 'luxon'
import CarpoolingAd from './CarpoolingAd'
import HelpRequest from './HelpRequest'
import Offer from './Offer'

export default class User extends BaseModel {
@column({ isPrimary: true })
Expand All @@ -20,6 +23,15 @@ export default class User extends BaseModel {
@column()
public fingerprint: string

@hasMany(() => CarpoolingAd)
public carpoolingAds: HasMany<typeof CarpoolingAd>

@hasMany(() => Offer)
public offers: HasMany<typeof Offer>

@hasMany(() => HelpRequest)
public helpRequests: HasMany<typeof HelpRequest>

@column.dateTime({ autoCreate: true })
public createdAt: DateTime

Expand Down
2 changes: 1 addition & 1 deletion apps/api/config/cors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const corsConfig: CorsConfig = {
| you can define a function to enable/disable it on per request basis as well.
|
*/
enabled: false,
enabled: true,

// You can also use a function that return true or false.
// enabled: (request) => request.url().startsWith('/api')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default class extends BaseSchema {
table.string('phone').nullable()
table.string('email').nullable()
table.boolean('is_on_site').defaultTo(false).notNullable()
table.integer('user_id').unsigned().references('users.id')

/**
* Uses timestamptz for PostgreSQL and DATETIME2 for MSSQL
Expand Down
1 change: 1 addition & 0 deletions apps/api/database/migrations/1694627889396_offers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default class extends BaseSchema {
table.string('phone').nullable()
table.string('email').nullable()
table.boolean('is_on_site').defaultTo(false).notNullable()
table.integer('user_id').unsigned().references('users.id')

/**
* Uses timestamptz for PostgreSQL and DATETIME2 for MSSQL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default class extends BaseSchema {
table.integer('storage_space').nullable()

table.enum('status', Object.values(CarpoolingStatus)).notNullable()
table.integer('user_id').unsigned().references('users.id')

/**
* Uses timestamptz for PostgreSQL and DATETIME2 for MSSQL
Expand Down
2 changes: 1 addition & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"build"
],
"prettier": {
"trailingComma": "es5",
"trailingComma": "none",
"semi": false,
"singleQuote": true,
"useTabs": false,
Expand Down
2 changes: 2 additions & 0 deletions apps/api/start/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ Route.resource('users', 'UsersController')
Route.post('/register', 'AuthController.register')
Route.post('/login', 'AuthController.login')
Route.post('/logout', 'AuthController.logout').middleware('auth:api')

Route.post('/authenticate', 'AuthController.authenticate')
5 changes: 4 additions & 1 deletion apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"dependencies": {
"@capacitor/android": "^5.3.0",
"@capacitor/core": "^5.3.0",
"@fingerprintjs/fingerprintjs": "^4.0.1",
"@hookform/resolvers": "^3.3.1",
"@radix-ui/react-dialog": "^1.0.4",
"@radix-ui/react-icons": "^1.3.0",
Expand All @@ -23,6 +24,7 @@
"@radix-ui/react-select": "^1.2.2",
"@radix-ui/react-slot": "^1.0.2",
"@tanstack/react-query": "^4.35.3",
"@tanstack/react-query-devtools": "^4.35.3",
"axios": "^1.5.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
Expand All @@ -47,7 +49,8 @@
"tailwind-merge": "^1.14.0",
"tailwindcss-animate": "^1.0.7",
"vite-plugin-svgr": "^3.2.0",
"zod": "^3.22.2"
"zod": "^3.22.2",
"zustand": "^4.4.1"
},
"devDependencies": {
"@capacitor/cli": "^5.3.0",
Expand Down
6 changes: 3 additions & 3 deletions apps/app/src/components/atoms/action-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { ReactComponent as PlusIcon } from '@/assets/icons/plus.svg';
import { Popover, PopoverContent, PopoverTrigger } from '@/components/atoms/popover';
import { cn } from '@/lib/utils';
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import { Button } from './button';
import LoadingSpinner from './loading-spinner';
import { useTranslation } from 'react-i18next';

interface ActionButtonProps {
className?: string;
Expand Down Expand Up @@ -38,12 +38,12 @@ const ActionButton = ({ className, asSubmit, loading, disabled }: ActionButtonPr
return (
<Popover>
<PopoverTrigger>
<button
<div
className={cn(' w-16 h-16 bg-red-800 rounded-full text-4xl flex justify-center items-center', className)}
onClick={() => setOpen(!open)}
>
<PlusIcon className={cn('transform transition-transform duration-300', open && 'rotate-45')} />
</button>
</div>
</PopoverTrigger>
<PopoverContent align="center" className="w-screen" side="top" sideOffset={50}>
<div className="flex flex-col gap-4 py-4">
Expand Down
12 changes: 5 additions & 7 deletions apps/app/src/components/molecules/FilterButton.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import { ReactComponent as FilterIcon } from '@/assets/icons/filter.svg';
import { Popover, PopoverContent, PopoverTrigger } from '@/components/atoms/popover';
import { RequestTypes } from '@/types/types';
import { FixType } from '@/types/utils';
import { Badge } from '../atoms/badge';
import { Button } from '../atoms/button';

import { ReactComponent as FoodIcon } from '@/assets/icons/food.svg';
import { ReactComponent as MarkerIcon } from '@/assets/icons/marker.svg';
import { ReactComponent as MedicalIcon } from '@/assets/icons/medical.svg';
import { ReactComponent as RiskIcon } from '@/assets/icons/risk.svg';
import { ReactComponent as ShelterIcon } from '@/assets/icons/shelter.svg';
import { ReactComponent as SortIcon } from '@/assets/icons/sort.svg';
import { ReactComponent as StatusIcon } from '@/assets/icons/status.svg';
import { Popover, PopoverContent, PopoverTrigger } from '@/components/atoms/popover';
import { RequestTypes } from '@/types/types';
import { FixType } from '@/types/utils';
import { Crosshair2Icon } from '@radix-ui/react-icons';
import { ReactNode } from 'react';
import { useTranslation } from 'react-i18next';
import { Badge } from '../atoms/badge';
import { Button } from '../atoms/button';
import IconInput from './icon-input';
import IconSelect from './icon-select';

type Filter = FixType;

interface FilterProps {
filters?: Filter[];
onFilter?: (filters: Filter[]) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { cn } from '@/lib/utils';
import { BaseInputProps } from '@/types/form';
import { RequestTypes } from '@/types/types';
import { forwardRef } from 'react';
import AssistanceTypeBlock from '../atoms/assistance-type-block';
import { useTranslation } from 'react-i18next';
import AssistanceTypeBlock from '../atoms/assistance-type-block';

interface AssistanceTypeProps extends BaseInputProps {
value: RequestTypes[];
Expand Down
6 changes: 3 additions & 3 deletions apps/app/src/components/molecules/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { ReactComponent as RiskIcon } from '@/assets/icons/risk.svg';
import { ReactComponent as ShelterIcon } from '@/assets/icons/shelter.svg';
import { cn } from '@/lib/utils';
import { ArrowRightIcon } from '@radix-ui/react-icons';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import { Badge } from '../atoms/badge';
import { useTranslation } from 'react-i18next';

interface CardProps {
className?: string;
Expand Down Expand Up @@ -34,8 +34,8 @@ const Card = ({ className }: CardProps) => {
<div className="flex items-center gap-2">
<ShelterIcon className="w-5 h-5" />
<FoodIcon className="w-6 h-6 text-teal-500" />
<RiskIcon className="w-5 h-5" />
<MedicalIcon className="w-5 h-5" />
<RiskIcon className="w-5 h-5 text-red-500" />
<MedicalIcon className="w-5 h-5 text-red-500" />
</div>
</div>
<div className="flex justify-between items-center">
Expand Down
6 changes: 3 additions & 3 deletions apps/app/src/components/molecules/header.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { cn } from '@/lib/utils';
import { useApp } from '@/providers/app-provider';
import { useTheme } from '@/providers/theme-provider';
import BackButton from '../atoms/back-button';
import Language from '../atoms/language';
import { useTheme } from '@/providers/theme-provider';

const Header = () => {
const { showBackButton } = useApp();
const { theme } = useTheme();

return (
<header className="flex justify-between h-10 m-6">
<header className="flex justify-between w-full p-6">
<BackButton
className={cn({
'opacity-0': !showBackButton
})}
/>
<img src={theme === 'dark' ? '/logo-light.svg' : 'logo.svg'} alt="logo" className="object-cover h-full" />
<img src={theme === 'dark' ? '/logo-light.svg' : 'logo.svg'} alt="logo" className="object-cover h-10" />
<Language />
</header>
);
Expand Down
38 changes: 20 additions & 18 deletions apps/app/src/components/templates/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import Providers from '@/providers';
import { useTheme } from '@/providers/theme-provider';
import ThemeProvider, { useTheme } from '@/providers/theme-provider';
import { Suspense } from 'react';
import { isBrowser } from 'react-device-detect';
import { useTranslation } from 'react-i18next';
import { Outlet, useLocation } from 'react-router-dom';
import LoadingSpinner from '../atoms/loading-spinner';
import Header from '../molecules/header';
import Navbar from '../molecules/navbar';

const Logo = () => {
const { theme } = useTheme();

return <img src={theme === 'dark' ? '/logo-light.svg' : 'logo.svg'} alt="logo" className="h-32 mx-auto my-8" />;
};

Expand All @@ -21,30 +22,31 @@ const Layout = () => {

document.body.dir = i18n.dir();

// const query = useApi<'login'>('login', 'test');

// const { isSuccess, isLoading } = query;

return (
<Providers>
{isBrowser ? (
<div className="flex w-screen h-screen bg-current">
if (isBrowser) {
return (
<ThemeProvider>
<div className="flex w-screen h-screen bg-background">
<div className="flex m-auto flex-col">
<img src="/logo-light.svg" alt="logo" className="h-32 mx-auto my-8" />
<Logo />
<h1 className="text-center text-white ">Coming Soon...</h1>
<h1 className="text-center text-primary ">Coming Soon...</h1>
</div>
</div>
) : (
<>
</ThemeProvider>
);
}

return (
<Suspense fallback={<LoadingSpinner />}>
<Providers>
<div className="">
{!hideHeaderRoutes.some((route) => location.pathname.includes(route)) && <Header />}
<main className="flex flex-col w-screen overflow-auto h-[calc(100vh-100px)]">
<main className="flex flex-col flex-grow overflow-y-auto w-full">
<Outlet />
{!hideNavbarRoutes.some((route) => location.pathname.includes(route)) && <Navbar />}
</main>
</>
)}
</Providers>
</div>
</Providers>
</Suspense>
);
};

Expand Down
Loading

0 comments on commit bfeceaa

Please sign in to comment.