Skip to content

Commit

Permalink
Feat: check business registration number (#85)
Browse files Browse the repository at this point in the history
* feat: install axios

* feat: check business registration number

* feat: add ODCLOUD api key for ci
  • Loading branch information
raipen authored Nov 12, 2023
1 parent 845975f commit c007310
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 13 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
14 changes: 7 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@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",
Expand Down
2 changes: 1 addition & 1 deletion prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ async function main() {
const user = await prisma.user.create({
data: {
id: 1,
businessRegistrationNumber: '0123456789',
businessRegistrationNumber: '5133001104',
phoneNumber: '01012345678',
},
}); //user id 1
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 @@ -78,6 +79,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 !== '';
}
2 changes: 1 addition & 1 deletion test/integration/seedValues.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const user = {
id: 1,
businessRegistrationNumber: '0123456789',
businessRegistrationNumber: '5133001104',
phoneNumber: '01012345678',
};

Expand Down
2 changes: 1 addition & 1 deletion test/integration/storeService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { LoginToken } from '@utils/jwt';
let app: FastifyInstance;

const phone = '01011112222';
const businessRegistrationNumber = '1122233444';
const businessRegistrationNumber = '5133001104';
let accessToken: string;

beforeAll(async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/userService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ afterAll(async () => {
});

const phone = '01012345678';
const businessRegistrationNumber = '1234567890';
const businessRegistrationNumber = '5133001104';
let tokenForCertificatePhone: string;
let certificatedPhoneToken: string;
let accessToken: string;
Expand Down
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 c007310

Please sign in to comment.