Skip to content

Commit

Permalink
Feat/accept invite (#53)
Browse files Browse the repository at this point in the history
* feat: InviteInfo 테이블 추가

* feat: 초대권 생성 기능 구현

* feat: trpcModule, userModule에 inviteModule 추가

* feat: 회원가입시 초대권 생성 코드 추가

* chore: 코드 포맷팅 및 console.log 제거

* chore: 줄 띄어쓰기 추가

* feat: 내 초대권 조회 기능 추가

* feat: trpc router에 InviteController 연결

* feat: controller에서 사용하는 모듈들을 상대경로로 import 변경

* client에서 사용할 때, trpc에서 invite router의 타입을 any로 잡혀서 상대경로로 변경

* feat: 내 초대권 조회 기능 테스트 추가

* feat: code를 uid에서 랜덤 6자로 변경

* refactor: 불필요한 기본값 설정 제거

* refactor: 초대한 수 기록하는 변수에 기본값 설정 제거

* wip migration 필요해서 브랜치를 옮기기 위한 커밋

* feat: add user type  for non invite user

* [#46] 초대권 생성 기능 구현 (#48)

* feat: InviteInfo 테이블 추가

* feat: 초대권 생성 기능 구현

* feat: trpcModule, userModule에 inviteModule 추가

* feat: 회원가입시 초대권 생성 코드 추가

* chore: 코드 포맷팅 및 console.log 제거

* chore: 줄 띄어쓰기 추가

* feat: 내 초대권 조회 기능 추가

* feat: trpc router에 InviteController 연결

* feat: controller에서 사용하는 모듈들을 상대경로로 import 변경

* client에서 사용할 때, trpc에서 invite router의 타입을 any로 잡혀서 상대경로로 변경

* feat: 내 초대권 조회 기능 테스트 추가

* feat: code를 uid에서 랜덤 6자로 변경

* refactor: 불필요한 기본값 설정 제거

* refactor: 초대한 수 기록하는 변수에 기본값 설정 제거

* feat: add user type  for non invite user

* fix: default userType변경 및 inviteCode에 unique 추가

* fix: default userType변경 및 inviteCode에 unique 추가

* fix: inviteUser 테이블에 User relation연결
schema상에서만 연결처럼 보이고 실제 db에서는 연결 안됨
실제 연결시키려면 schema.prisma에서 relationMode를 foreignKeys로 설정해야함

* fix: inviteUser 테이블에 User relation연결
schema상에서만 연결처럼 보이고 실제 db에서는 연결 안됨
실제 연결시키려면 schema.prisma에서 relationMode를 foreignKeys로 설정해야함

* feat: ctx에 user 타입 캐스팅 해두기
#50

* feat: add inviteRecord table

* feat: add inviteRecord table

* fix: 연결관계 추가 및 인덱스 추가

* fix: 연결관계 추가 및 인덱스 추가

* fix: test

* fix: test

* wip

* fix: 회원가입 시 초대권이 생성되지 않고, 초대 시 생성되도록 변경

* feat: 클립보드 라이브러리 추가 및 패키지 고정

* feat: 초대 승인 기능

* fix: 코드 수정

* fix: default 설정을 받을 수 있는

* wip

---------

Co-authored-by: yoon-junseo <[email protected]>
Co-authored-by: bongsu-rapportlabs <[email protected]>
  • Loading branch information
3 people authored Jul 11, 2024
1 parent 74fe8df commit 1d29da1
Show file tree
Hide file tree
Showing 29 changed files with 7,827 additions and 10,016 deletions.
16 changes: 11 additions & 5 deletions apps/app/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -908,9 +908,9 @@ PODS:
- MMKV (>= 1.3.3)
- RCT-Folly (= 2022.05.16.00)
- React-Core
- react-native-safe-area-context (4.10.5):
- react-native-safe-area-context (4.10.7):
- React-Core
- react-native-webview (13.10.3):
- react-native-webview (13.10.4):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
Expand Down Expand Up @@ -1081,6 +1081,8 @@ PODS:
- React-jsi (= 0.73.8)
- React-logger (= 0.73.8)
- React-perflogger (= 0.73.8)
- RNCClipboard (1.14.1):
- React-Core
- RNGoogleSignin (11.0.1):
- GoogleSignIn (~> 7.0.0)
- React-Core
Expand Down Expand Up @@ -1148,6 +1150,7 @@ DEPENDENCIES:
- React-runtimescheduler (from `../node_modules/react-native/ReactCommon/react/renderer/runtimescheduler`)
- React-utils (from `../node_modules/react-native/ReactCommon/react/utils`)
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
- "RNCClipboard (from `../node_modules/@react-native-clipboard/clipboard`)"
- "RNGoogleSignin (from `../node_modules/@react-native-google-signin/google-signin`)"
- RNLocalize (from `../node_modules/react-native-localize`)
- RNScreens (from `../node_modules/react-native-screens`)
Expand Down Expand Up @@ -1267,6 +1270,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/react/utils"
ReactCommon:
:path: "../node_modules/react-native/ReactCommon"
RNCClipboard:
:path: "../node_modules/@react-native-clipboard/clipboard"
RNGoogleSignin:
:path: "../node_modules/@react-native-google-signin/google-signin"
RNLocalize:
Expand Down Expand Up @@ -1313,8 +1318,8 @@ SPEC CHECKSUMS:
React-logger: 60afd40b183e8e6642bfd0108f1a1ad360cc665e
React-Mapbuffer: 672a9342eb75a4d0663306e94d4dfc88aee73b93
react-native-mmkv: 1fdc81aa70c1aba09370718e6a63a09cbbbac8d2
react-native-safe-area-context: a240ad4b683349e48b1d51fed1611138d1bdad97
react-native-webview: d2116987f3a75ba677a9f49565bae6834d0e12c4
react-native-safe-area-context: 422017db8bcabbada9ad607d010996c56713234c
react-native-webview: dbc8171113daa2abb2499da5f327a8d0cdfcd61c
React-nativeconfig: 2e44d0d2dd222b12a5183f4bcaa4a91881497acb
React-NativeModulesApple: 8aa032fe6c92c1a3c63e4809d42816284a56a9b0
React-perflogger: f9367428cf475f4606b5965c1d5a71781bb95299
Expand All @@ -1335,11 +1340,12 @@ SPEC CHECKSUMS:
React-runtimescheduler: 1c40cfe98dcc7b06354d96a1cd8ee10cbc4cc797
React-utils: 4cc2ba652f5df1c8f0461d4ae9e3ee474c1354ea
ReactCommon: 1da3fc14d904883c46327b3322325eebf60a720a
RNCClipboard: 0a720adef5ec193aa0e3de24c3977222c7e52a37
RNGoogleSignin: 24d3b3261f78b0fae0aa013f8ab6f8d25e369b0c
RNLocalize: b77875884750cb6a58cd6865863fe2ba2729b72b
RNScreens: e842cdccb23c0a084bd6307f6fa83fd1c1738029
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
Yoga: 2a16e58450c48e110211dae1159fb114bbcdcfc0
Yoga: e5b887426cee15d2a326bdd34afc0282fc0486ad

PODFILE CHECKSUM: 0a0c59f84db5a439364725b3317225198053afb0

Expand Down
10 changes: 9 additions & 1 deletion apps/app/ios/app/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,17 @@
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<false/>
<true/>
<key>NSAllowsLocalNetworking</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>localhost</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
Expand Down
10 changes: 6 additions & 4 deletions apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dependencies": {
"@pinit/server": "workspace:^",
"@pinit/shared": "workspace:^",
"@react-native-clipboard/clipboard": "^1.14.1",
"@react-native-google-signin/google-signin": "^11.0.1",
"@react-navigation/bottom-tabs": "^6.5.20",
"@react-navigation/native": "^6.1.17",
Expand All @@ -32,18 +33,19 @@
"react-native-safe-area-context": "^4.10.4",
"react-native-screens": "^3.31.1",
"react-native-webview": "^13.8.6",
"rxjs": "^7.8.1"
"rxjs": "^7.8.1",
"zustand": "^4.5.4"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@babel/preset-env": "^7.20.0",
"@babel/runtime": "^7.24.4",
"@pinit/eslint-config": "workspace:*",
"@react-native-community/cli-platform-android": "^13.6.6",
"@react-native/babel-preset": "0.73.21",
"@react-native/babel-preset": "^0.73.21",
"@react-native/gradle-plugin": "^0.73.2",
"@react-native/metro-config": "0.73.5",
"@react-native/typescript-config": "0.73.1",
"@react-native/metro-config": "^0.73.5",
"@react-native/typescript-config": "^0.73.1",
"@rnx-kit/metro-config": "^1.3.15",
"@rnx-kit/metro-resolver-symlinks": "^0.1.36",
"@types/react": "^18.2.6",
Expand Down
4 changes: 4 additions & 0 deletions apps/app/src/shared/hocs/withInvite.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const withInvite = {
bottomSheet: () => {},
redirectScreen: () => {},
}
4 changes: 4 additions & 0 deletions apps/app/src/shared/hocs/withLogin.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const withLogin = {
bottomSheet: () => {},
redirectScreen: () => {},
}
7 changes: 5 additions & 2 deletions apps/app/src/shared/storage/Auth/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MMKVWrapper } from '@/shared/storage'
import { STORAGE_KEY } from '@/shared/storage/constants'
import MMKVWrapper from '..'
import { STORAGE_KEY } from '../constants'

class AuthStorage extends MMKVWrapper<string> {
setToken(item: string) {
Expand All @@ -9,6 +9,9 @@ class AuthStorage extends MMKVWrapper<string> {
getToken() {
return this.getItem() ?? ''
}
removeToken() {
this.removeItem()
}
}

const authStorage = new AuthStorage(STORAGE_KEY.auth)
Expand Down
1 change: 1 addition & 0 deletions apps/app/src/shared/stores/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TODO 로그인 유저 정보 물고있기
26 changes: 26 additions & 0 deletions apps/app/src/shared/stores/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { trpc } from './../trpc/index'
import { create } from 'zustand'
import { User } from '@pinit/server/src/prisma/dto'

type UserStore = {
_user?: User
user: User
ininUser: () => Promise<void>
}

export const useUser = create<UserStore>()((set, get) => ({
_user: undefined,
user: (() => {
const _user = get()._user
if (!_user) {
get().ininUser()
throw new Error('user가 없습니다.')
}

return _user
})(),
ininUser: async () => {
const user = await trpc.user.getUser.query()
set({ user })
},
}))
6 changes: 3 additions & 3 deletions apps/app/src/shared/trpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import authStorage from '@/shared/storage/Auth'
export const trpcOption = {
links: [
httpBatchLink({
// url: 'http://172.30.1.54:8080/trpc', // you should update this to use env variables
url: 'http://localhost:8080/trpc', // you should update this to use env variables
// url: 'http://localhost:8080/trpc', // you should update this to use env variables
// url, // you should update this to use env variables
headers() {
return {
Authorization: `Bearer ${authStorage.getToken()}`,
Expand All @@ -19,7 +22,4 @@ export const trpcOption = {
}

export const trpcQuery = createTRPCReact<AppRouter>()
// react-query 같이쓰게하면 해당 api가 deprecated되는데
// 사용상에는 지장이 없어서 사용.
// 후에 버전올릴 때 이슈 있으면 대응 필요
export const trpc = createTRPCProxyClient<AppRouter>(trpcOption)
4 changes: 4 additions & 0 deletions apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"scripts": {
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"create-migration": "pnpx prisma migrate dev --create-only",
"deploy-migration": "pnpx prisma migrate deploy",
"prisma-generate": "pnpx prisma generate",
"prisma-format": "pnpx prisma format",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE `User` MODIFY `type` ENUM('USER_NOT_INVITED', 'USER', 'ADMIN') NOT NULL DEFAULT 'USER';
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
Warnings:
- A unique constraint covering the columns `[code]` on the table `InviteInfo` will be added. If there are existing duplicate values, this will fail.
*/
-- AlterTable
ALTER TABLE `User` MODIFY `type` ENUM('USER_NOT_INVITED', 'USER', 'ADMIN') NOT NULL DEFAULT 'USER_NOT_INVITED';

-- CreateIndex
CREATE UNIQUE INDEX `InviteInfo_code_key` ON `InviteInfo`(`code`);
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- CreateTable
CREATE TABLE `InviteRecord` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`inviteeUid` VARCHAR(191) NOT NULL,
`inviterUid` VARCHAR(191) NOT NULL,
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- DropIndex
DROP INDEX `InviteTier_tier_key` ON `InviteTier`;

-- AlterTable
ALTER TABLE `InviteTier` ADD PRIMARY KEY (`tier`);

-- CreateIndex
CREATE INDEX `InviteInfo_tier_idx` ON `InviteInfo`(`tier`);

-- CreateIndex
CREATE INDEX `InviteInfo_code_idx` ON `InviteInfo`(`code`);

-- CreateIndex
CREATE INDEX `InviteInfo_uid_idx` ON `InviteInfo`(`uid`);

-- CreateIndex
CREATE INDEX `InviteTier_tier_idx` ON `InviteTier`(`tier`);
57 changes: 39 additions & 18 deletions apps/server/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ generator client {
generator zod {
provider = "pnpx zod-prisma-types"
output = "../src/prisma/dto"
createRelationValuesTypes = true
createInputTypes = false
}

datasource db {
Expand All @@ -15,13 +18,14 @@ datasource db {
}

model User {
name String @default("")
createdAt DateTime @default(now())
imageUrl String?
deletedAt DateTime?
updatedAt DateTime @default(now())
uid String @id
type Type @default(USER)
name String @default("")
createdAt DateTime @default(now())
imageUrl String?
deletedAt DateTime?
updatedAt DateTime @default(now())
uid String @id
type User_type @default(USER_NOT_INVITED)
InviteInfo InviteInfo? @relation("UserInviteInfo")
}

model GoogleProfile {
Expand All @@ -37,21 +41,38 @@ model GoogleProfile {
}

model InviteTier {
tier String @unique
tier String @id
availableAmount Int
inviteInfo InviteInfo[] @relation("UserInviteTier")
@@index([tier])
}

model InviteInfo {
uid String @id
code String @unique
tier String
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
availableInviteCount Int
inviteHistoryCount Int @default(0)
user User? @relation("UserInviteInfo", fields: [uid], references: [uid])
inviterTier InviteTier? @relation("UserInviteTier", fields: [tier], references: [tier])
@@index([tier])
@@index([code])
@@index([uid])
}

enum Type {
enum User_type {
USER_NOT_INVITED
USER
ADMIN
}

model InviteInfo {
uid String @id
code String
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
availableInviteCount Int
inviteHistoryCount Int @default(0)
tier String
}
model InviteRecord {
id Int @id @default(autoincrement())
inviteeUid String
inviterUid String
createdAt DateTime @default(now())
}
10 changes: 10 additions & 0 deletions apps/server/src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Controller, Get } from '@nestjs/common'
import { TRPCError } from '@trpc/server'

@Controller('/')
export class AppController {
@Get('/')
async test() {
return 'hello world'
}
}
2 changes: 2 additions & 0 deletions apps/server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { PrismaService } from './prisma/prisma.service'
import { ConfigModule } from '@nestjs/config'
import { PrismaModule } from './prisma/prisma.module'
import { AuthModule } from './auth/auth.module'
import { AppController } from './app.controller'

@Module({
imports: [
Expand All @@ -18,5 +19,6 @@ import { AuthModule } from './auth/auth.module'
AuthModule,
],
providers: [AppService, PrismaService],
controllers: [AppController],
})
export class AppModule {}
9 changes: 6 additions & 3 deletions apps/server/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ export class AuthService {
throw new HttpException('잘못된 로그인 입니다.', 405)
}

return await this.jwtService.signAsync(user, {
secret: JWT_SECRET,
})
return await this.jwtService.signAsync(
{ uid: user.uid },
{
secret: JWT_SECRET,
},
)
}

decodeJWT(token: string) {
Expand Down
Loading

0 comments on commit 1d29da1

Please sign in to comment.