Skip to content

Commit

Permalink
feat(health): add health checks to server api
Browse files Browse the repository at this point in the history
  • Loading branch information
AmruthPillai committed Mar 10, 2022
1 parent 8f48f5f commit eca80a1
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 26 deletions.
2 changes: 1 addition & 1 deletion client/components/build/LeftSidebar/sections/Profiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const Profiles = () => {
<footer className="flex justify-end">
<Button variant="outlined" startIcon={<Add />} onClick={handleAdd}>
{t('builder.common.actions.add', {
section: t('builder.leftSidebar.sections.profiles.heading', { count: 1 }),
token: t('builder.leftSidebar.sections.profiles.heading', { count: 1 }),
})}
</Button>
</footer>
Expand Down
2 changes: 1 addition & 1 deletion client/modals/auth/LoginModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const LoginModal: React.FC = () => {
startIcon={<Google />}
onClick={handleLoginWithGoogle}
>
{t('modals.auth.login.actions.login-google')}
{t('modals.auth.login.actions.google')}
</Button>

<Button type="submit" onClick={handleSubmit(onSubmit)} disabled={isLoading}>
Expand Down
42 changes: 36 additions & 6 deletions client/modals/auth/RegisterModal.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import env from '@beam-australia/react-env';
import { joiResolver } from '@hookform/resolvers/joi';
import { HowToReg } from '@mui/icons-material';
import { Google, HowToReg } from '@mui/icons-material';
import { Button, TextField } from '@mui/material';
import Joi from 'joi';
import { Trans, useTranslation } from 'next-i18next';
import { GoogleLoginResponse, GoogleLoginResponseOffline, useGoogleLogin } from 'react-google-login';
import { Controller, useForm } from 'react-hook-form';
import { useMutation } from 'react-query';

import BaseModal from '@/components/shared/BaseModal';
import { register as registerUser, RegisterParams } from '@/services/auth';
import { loginWithGoogle, LoginWithGoogleParams, register as registerUser, RegisterParams } from '@/services/auth';
import { ServerError } from '@/services/axios';
import { useAppDispatch, useAppSelector } from '@/store/hooks';
import { setModalState } from '@/store/modal/modalSlice';
Expand Down Expand Up @@ -56,14 +58,26 @@ const RegisterModal: React.FC = () => {

const { mutateAsync, isLoading } = useMutation<void, ServerError, RegisterParams>(registerUser);

const { mutateAsync: loginWithGoogleMutation } = useMutation<void, ServerError, LoginWithGoogleParams>(
loginWithGoogle
);

const { signIn } = useGoogleLogin({
clientId: env('GOOGLE_CLIENT_ID'),
onSuccess: async (response: GoogleLoginResponse | GoogleLoginResponseOffline) => {
await loginWithGoogleMutation({ accessToken: (response as GoogleLoginResponse).accessToken });

handleClose();
},
});

const handleClose = () => {
dispatch(setModalState({ modal: 'auth.register', state: { open: false } }));
reset();
};

const onSubmit = async ({ name, username, email, password }: FormData) => {
await mutateAsync({ name, username, email, password });

handleClose();
};

Expand All @@ -72,16 +86,32 @@ const RegisterModal: React.FC = () => {
dispatch(setModalState({ modal: 'auth.login', state: { open: true } }));
};

const handleLoginWithGoogle = () => {
signIn();
};

return (
<BaseModal
icon={<HowToReg />}
isOpen={isOpen}
heading={t('modals.auth.register.heading')}
handleClose={handleClose}
footerChildren={
<Button type="submit" onClick={handleSubmit(onSubmit)} disabled={isLoading}>
{t('modals.auth.register.actions.register')}
</Button>
<>
<Button
type="submit"
variant="outlined"
disabled={isLoading}
startIcon={<Google />}
onClick={handleLoginWithGoogle}
>
{t('modals.auth.register.actions.google')}
</Button>

<Button type="submit" onClick={handleSubmit(onSubmit)} disabled={isLoading}>
{t('modals.auth.register.actions.register')}
</Button>
</>
}
>
<p>{t('modals.auth.register.body')}</p>
Expand Down
4 changes: 2 additions & 2 deletions client/modals/builder/sections/ProfileModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ const ProfileModal: React.FC = () => {
const isEditMode = useMemo(() => !!item, [item]);

const addText = t('builder.common.actions.add', {
section: t('builder.leftSidebar.sections.profiles.heading', { count: 1 }),
token: t('builder.leftSidebar.sections.profiles.heading', { count: 1 }),
});
const editText = t('builder.common.actions.edit', {
section: t('builder.leftSidebar.sections.profiles.heading', { count: 1 }),
token: t('builder.leftSidebar.sections.profiles.heading', { count: 1 }),
});

const { reset, control, handleSubmit } = useForm<FormData>({
Expand Down
24 changes: 12 additions & 12 deletions client/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,6 @@ const Home: NextPage = () => {
<h6>{t('landing.links.heading')}</h6>

<div>
<a href={GITHUB_URL} target="_blank" rel="noreferrer">
<Button variant="text" startIcon={<LinkIcon />}>
{t('landing.links.links.github')}
</Button>
</a>

<a href={DONATION_URL} target="_blank" rel="noreferrer">
<Button variant="text" startIcon={<LinkIcon />}>
{t('landing.links.links.donate')}
</Button>
</a>

<Link href="/meta/privacy" passHref>
<Button variant="text" startIcon={<LinkIcon />}>
{t('landing.links.links.privacy')}
Expand All @@ -170,6 +158,18 @@ const Home: NextPage = () => {
{t('landing.links.links.service')}
</Button>
</Link>

<a href={GITHUB_URL} target="_blank" rel="noreferrer">
<Button variant="text" startIcon={<LinkIcon />}>
{t('landing.links.links.github')}
</Button>
</a>

<a href={DONATION_URL} target="_blank" rel="noreferrer">
<Button variant="text" startIcon={<LinkIcon />}>
{t('landing.links.links.donate')}
</Button>
</a>
</div>
</section>

Expand Down
7 changes: 4 additions & 3 deletions client/public/locales/en/modals.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"login": {
"actions": {
"login": "Login",
"login-google": "Login with Google"
"google": "Login with Google"
},
"body": "Please enter your username and password associated with your account to login and access, manage and share your resumes.",
"form": {
Expand All @@ -34,7 +34,8 @@
},
"register": {
"actions": {
"register": "Register"
"register": "Register",
"google": "Register with Google"
},
"body": "Please enter your personal information to create an account.",
"form": {
Expand Down Expand Up @@ -112,7 +113,7 @@
"actions": {
"upload-json": "Upload JSON"
},
"body": "If you have a JSON that was exported with the current version of Reactive Resume, you can import it back here to get an editable version again.",
"body": "If you have a JSON that was exported with the current version of Reactive Resume, you can import it back here to get an editable version again. Previous versions of Reactive Resume are unfortunately not supported at the moment.",
"heading": "Import From Reactive Resume"
}
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reactive-resume",
"version": "3.0.0-beta.2",
"version": "3.0.0-beta.4",
"private": true,
"workspaces": [
"schema",
Expand Down
22 changes: 22 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@nestjs/platform-express": "^8.4.0",
"@nestjs/schedule": "^1.0.2",
"@nestjs/serve-static": "^2.2.2",
"@nestjs/terminus": "^8.0.4",
"@nestjs/typeorm": "^8.0.3",
"@sendgrid/mail": "^7.6.1",
"@types/passport": "^1.0.7",
Expand Down
2 changes: 2 additions & 0 deletions server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ConfigModule } from './config/config.module';
import { DatabaseModule } from './database/database.module';
import { HttpExceptionFilter } from './filters/http-exception.filter';
import { FontsModule } from './fonts/fonts.module';
import { HealthModule } from './health/health.module';
import { IntegrationsModule } from './integrations/integrations.module';
import { MailModule } from './mail/mail.module';
import { PrinterModule } from './printer/printer.module';
Expand All @@ -32,6 +33,7 @@ import { UsersModule } from './users/users.module';
FontsModule,
IntegrationsModule,
PrinterModule,
HealthModule,
],
providers: [
{
Expand Down
21 changes: 21 additions & 0 deletions server/src/health/health.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Controller, Get } from '@nestjs/common';
import { HealthCheck, HealthCheckService, HttpHealthIndicator, TypeOrmHealthIndicator } from '@nestjs/terminus';

@Controller('health')
export class HealthController {
constructor(
private health: HealthCheckService,
private db: TypeOrmHealthIndicator,
private http: HttpHealthIndicator
) {}

@Get()
@HealthCheck()
check() {
return this.health.check([
() => this.db.pingCheck('database'),
() => this.http.pingCheck('app', 'https://rxresu.me'),
() => this.http.pingCheck('docs', 'https://beta.rxresu.me'),
]);
}
}
11 changes: 11 additions & 0 deletions server/src/health/health.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { HttpModule } from '@nestjs/axios';
import { Module } from '@nestjs/common';
import { TerminusModule } from '@nestjs/terminus';

import { HealthController } from './health.controller';

@Module({
imports: [HttpModule, TerminusModule],
controllers: [HealthController],
})
export class HealthModule {}

0 comments on commit eca80a1

Please sign in to comment.