Skip to content

Commit

Permalink
Merge branch 'dev' into refactor/testing
Browse files Browse the repository at this point in the history
  • Loading branch information
raipen committed Nov 18, 2023
2 parents adca7e4 + 0de523e commit bfb4cc0
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 42 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ jobs:
- name: start db & set .env
run: |
sudo service mysql start
echo DATABASE_URL=mysql://root:root@localhost:3306/db > .env
echo "DATABASE_URL=mysql://root:root@localhost:3306/db
ODCLOUD_API_KEY=${{ secrets.ODCLOUD_API_KEY }}" > .env
- name: Install Dependencies & db setup
run: |
npm install
Expand Down
30 changes: 23 additions & 7 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
"@sentry/node": "^7.73.0",
"@sentry/profiling-node": "^1.2.1",
"@types/jsonwebtoken": "^9.0.2",
"axios": "^1.6.0",
"axios": "^1.6.1",
"crypto": "^1.0.1",
"crypto-js": "^4.2.0",
"dotenv": "^16.3.1",
"fastify": "^4.19.1",
"fastify-plugin": "^4.5.0",
"fastify-schema-to-ts": "^1.0.1",
"json-schema-to-ts": "^2.9.2",
"jsonwebtoken": "^9.0.1"
},
Expand Down
26 changes: 0 additions & 26 deletions src/DTO/index.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,3 @@ export type ErrorInterface = FromSchema<{
toast: { type: 'string', enum: string[] }
}
}>;

export type SchemaToInterface<
T extends {
body?: JSONSchema;
querystring?: JSONSchema;
params?: JSONSchema;
headers?: JSONSchema;
response: { [key: string]: JSONSchema };
},
Option extends [{ pattern: unknown; output: unknown }] | false = false
> = {
Body: T['body'] extends JSONSchema ? FromSchema<T['body']> : unknown;
Querystring: T['querystring'] extends JSONSchema
? FromSchema<T['querystring']>
: unknown;
Params: T['params'] extends JSONSchema ? FromSchema<T['params']> : unknown;
Headers: T['headers'] extends JSONSchema
? FromSchema<T['headers']>
: unknown;
Reply: {
[key in keyof T['response']]: FromSchema<
T['response'][key],
{ deserialize: Option }
>;
};
};
2 changes: 1 addition & 1 deletion src/DTO/menu.dto.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
StoreAuthorizationHeader,
errorSchema,
SchemaToInterface,
} from '@DTO/index.dto';
import * as E from '@errors';
import { SchemaToInterface } from 'fastify-schema-to-ts';

export const getMenuListSchema = {
tags: ['menu'],
Expand Down
2 changes: 1 addition & 1 deletion src/DTO/mileage.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Mileage as prismaMileage } from '@prisma/client';
import {
StoreAuthorizationHeader,
errorSchema,
SchemaToInterface,
} from '@DTO/index.dto';
import * as E from '@errors';
import { SchemaToInterface } from 'fastify-schema-to-ts';
export type Mileage = prismaMileage;

export const getMileageSchema = {
Expand Down
2 changes: 1 addition & 1 deletion src/DTO/order.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Order as prismaOrder } from '@prisma/client';
import {
StoreAuthorizationHeader,
errorSchema,
SchemaToInterface,
} from '@DTO/index.dto';
import * as E from '@errors';
import { SchemaToInterface } from 'fastify-schema-to-ts';
export type Order = prismaOrder;

export const newOrderSchema = {
Expand Down
2 changes: 1 addition & 1 deletion src/DTO/preOrder.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { PreOrder as prismaPreOrder } from '@prisma/client';
import {
StoreAuthorizationHeader,
errorSchema,
SchemaToInterface,
} from '@DTO/index.dto';
import * as E from '@errors';
import { SchemaToInterface } from 'fastify-schema-to-ts';
export type PreOrder = prismaPreOrder;

export const newPreOrderSchema = {
Expand Down
2 changes: 1 addition & 1 deletion src/DTO/stock.dto.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
StoreAuthorizationHeader,
errorSchema,
SchemaToInterface,
} from '@DTO/index.dto';
import * as E from '@errors';
import { SchemaToInterface } from 'fastify-schema-to-ts';

export const createStockSchema = {
tags: ['stock'],
Expand Down
2 changes: 1 addition & 1 deletion src/DTO/store.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { Store as prismaStore } from '@prisma/client';
import {
AuthorizationHeader,
errorSchema,
SchemaToInterface,
StoreAuthorizationHeader,
} from '@DTO/index.dto';
import * as E from '@errors';
import { SchemaToInterface } from 'fastify-schema-to-ts';
export type Store = prismaStore;

export const newStoreSchema = {
Expand Down
2 changes: 1 addition & 1 deletion src/DTO/user.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { User as prismaUser } from '@prisma/client';
import {
AuthorizationHeader,
errorSchema,
SchemaToInterface,
} from '@DTO/index.dto';
import * as E from '@errors';
import { SchemaToInterface } from 'fastify-schema-to-ts';
export type User = prismaUser;

export const phoneSchema = {
Expand Down
1 change: 1 addition & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Config{
NCP_SENS_ACCESS: process.env.NCP_SENS_ACCESS || '',
NCP_SENS_MY_NUMBER: process.env.NCP_SENS_MY_NUMBER || '',
NCP_SENS_ID: process.env.NCP_SENS_ID || '',
ODCLOUD_API_KEY: process.env.ODCLOUD_API_KEY || '',
} as const;
}

Expand Down
5 changes: 5 additions & 0 deletions src/services/userService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
LoginToken,
} from '@utils/jwt';
import * as E from '@errors';
import checkBusinessRegistrationNumber from '@utils/checkBusinessRegistrationNumber';

const prisma = new PrismaClient();

Expand Down Expand Up @@ -79,6 +80,10 @@ export default {
throw new E.UserAuthorizationError('토큰이 유효하지 않습니다.');
}

if(!await checkBusinessRegistrationNumber(businessRegistrationNumber)){
throw new E.UserAuthorizationError('사업자 등록번호가 유효하지 않습니다.');
}

let user = await prisma.user.findFirst({
where: {
businessRegistrationNumber: businessRegistrationNumber,
Expand Down
12 changes: 12 additions & 0 deletions src/utils/checkBusinessRegistrationNumber.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import axios from 'axios';
import config from '@config';

export default async (businessRegistrationNumber: string): Promise<boolean> => {
const { data } = await axios.post(
`https://api.odcloud.kr/api/nts-businessman/v1/status?serviceKey=${config.ODCLOUD_API_KEY}`,
{
b_no: [businessRegistrationNumber],
}
)
return data.data[0].b_stt_cd !== '';
}
9 changes: 9 additions & 0 deletions test/unit/businessNumber.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import checkBusinessRegistrationNumber from "@utils/checkBusinessRegistrationNumber";
import * as E from "@errors";
import { test, expect } from "@jest/globals";

test("checkBusinessRegistrationNumber", async () => {
expect(await checkBusinessRegistrationNumber("5133001104")).toBe(true);
expect(await checkBusinessRegistrationNumber("")).toBe(false);
expect(await checkBusinessRegistrationNumber("1234567890")).toBe(false);
});

0 comments on commit bfb4cc0

Please sign in to comment.