-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from TheWidlarzGroup/project-init
Mock api
- Loading branch information
Showing
4 changed files
with
145 additions
and
8 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
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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import {UserData} from 'src/types/UserData.types'; | ||
import {getRandomNumber} from '../utils/getRandomNumber'; | ||
|
||
const userEmpty: UserData = { | ||
name: 'John', | ||
surname: 'Doe', | ||
email: null, | ||
phone: null, | ||
street: null, | ||
city: null, | ||
code: null, | ||
country: null, | ||
account: null, | ||
creaditCardNo: null, | ||
creditCardExp: null, | ||
creditCardCvv: null, | ||
}; | ||
|
||
const userWithContact: UserData = { | ||
name: 'John', | ||
surname: 'Doe', | ||
email: '[email protected]', | ||
phone: '857 254 712', | ||
street: null, | ||
city: null, | ||
code: null, | ||
country: null, | ||
account: null, | ||
creaditCardNo: null, | ||
creditCardExp: null, | ||
creditCardCvv: null, | ||
}; | ||
|
||
const userWithAddress: UserData = { | ||
name: 'John', | ||
surname: 'Doe', | ||
email: '[email protected]', | ||
phone: '857 254 712', | ||
street: '18th Dev Street', | ||
city: 'South Dev City', | ||
code: '99-888', | ||
country: 'Devburg', | ||
account: null, | ||
creaditCardNo: null, | ||
creditCardExp: null, | ||
creditCardCvv: null, | ||
}; | ||
|
||
const userComplete: UserData = { | ||
name: 'John', | ||
surname: 'Doe', | ||
email: '[email protected]', | ||
phone: '857 254 712', | ||
street: '18th Dev Street', | ||
city: 'South Dev City', | ||
code: '99-888', | ||
country: 'Devburg', | ||
account: '23 4444 2222 3333 1112 2342', | ||
creaditCardNo: '1231 2312 3123 1231', | ||
creditCardExp: '01/23', | ||
creditCardCvv: '123', | ||
}; | ||
|
||
export const getUser = async (prevUser?: UserData) => { | ||
console.log('Pending...'); | ||
|
||
const scenario = getRandomNumber(1, 4); | ||
|
||
await new Promise(res => setTimeout(res, 1000)); | ||
|
||
if (prevUser) { | ||
return prevUser; | ||
} else { | ||
switch (scenario) { | ||
case 1: | ||
return userEmpty; | ||
case 2: | ||
return userWithContact; | ||
case 3: | ||
return userWithAddress; | ||
case 4: | ||
return userComplete; | ||
default: | ||
return userEmpty; | ||
} | ||
} | ||
}; | ||
|
||
export const updateUser = async (updated: UserData) => { | ||
console.log('Updating...'); | ||
|
||
await new Promise(res => setTimeout(res, 1000)); | ||
|
||
return updated; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export interface UserData { | ||
name: string | null; | ||
surname: string | null; | ||
// contact | ||
email: string | null; | ||
phone: string | null; | ||
// address | ||
street: string | null; | ||
city: string | null; | ||
code: string | null; | ||
country: string | null; | ||
// billing | ||
account: string | null; | ||
creaditCardNo: string | null; | ||
creditCardExp: string | null; | ||
creditCardCvv: string | null; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const getRandomNumber = (min: number, max: number) => { | ||
return Math.floor(Math.random() * (max + 1 - min) + min); | ||
}; |