-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
17 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 13 additions & 16 deletions
29
src/mocks/fakeDatabase/userDatabase/index.ts → ...ocks/fakeDatabase/resources/user/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,60 @@ | ||
import { ISignUpRequest } from '@/types/auth'; | ||
import { IDatabaseUser } from '../types/auth'; | ||
import { IValueResponseReturn } from '../types'; | ||
import { IDatabaseUser } from '../../types/auth'; | ||
|
||
const userDatabase = { | ||
GET: { | ||
Get: { | ||
list: () => { | ||
const localStorageUserList = localStorage.getItem('userList') ?? ''; | ||
const parsedUserList: IDatabaseUser[] = localStorageUserList ? JSON.parse(localStorageUserList) : []; | ||
return { | ||
code: 200, | ||
value: parsedUserList, | ||
message: '성공!', | ||
message: '회원목록 조회 성공', | ||
}; | ||
}, | ||
detail: ({ key, value }: { key: keyof IDatabaseUser; value: string }) => { | ||
try { | ||
const userList = (userDatabase.GET.list() as IValueResponseReturn<IDatabaseUser[]>).value; | ||
const userList = userDatabase.Get.list().value; | ||
const findUser = userList.find((element) => element[key] === value); | ||
if (!findUser) { | ||
return { | ||
code: 400, | ||
message: '회원정보가 존재하지 않습니다!', | ||
message: '회원정보가 없음.', | ||
}; | ||
} | ||
return { | ||
code: 200, | ||
message: '성공!', | ||
message: '회원 상세정보 조회 성공.', | ||
value: findUser, | ||
}; | ||
} catch (error: any) { | ||
console.log(error); | ||
return { | ||
code: 500, | ||
message: error, | ||
message: '사용자 상세정보 조회중 에러발생.', | ||
}; | ||
} | ||
}, | ||
}, | ||
CREATE: { | ||
Create: { | ||
user: (request: ISignUpRequest) => { | ||
try { | ||
const userList = (userDatabase.GET.list() as IValueResponseReturn<IDatabaseUser[]>).value; | ||
const userList = userDatabase.Get.list().value; | ||
const lastUserId = userList[userList.length] ? userList[userList.length].id : 0; | ||
localStorage.setItem('userList', JSON.stringify([...userList, { id: lastUserId + 1, ...request }])); | ||
return { | ||
code: 200, | ||
message: '회원가입 성공!', | ||
message: '사용자 등록 성공.', | ||
}; | ||
} catch (error: any) { | ||
console.log(error); | ||
return { | ||
code: 500, | ||
message: error, | ||
message: '사용자 정보 등록중 에러발생', | ||
}; | ||
} | ||
}, | ||
}, | ||
UPDATE: {}, | ||
DELETE: {}, | ||
Update: {}, | ||
Delete: {}, | ||
}; | ||
|
||
export default userDatabase; |