fix(striker-ui): add switch to use fake data

main
Tsu-ba-me 4 years ago
parent 256c732f8e
commit e9b0a0339f
  1. 22
      striker-ui/lib/Anvil/handleAPIFakeGetAllAnvil.ts
  2. 23
      striker-ui/lib/Anvil/handleAPIFakeGetOneAnvil.ts
  3. 15
      striker-ui/lib/Anvil/handleAPIGetAllAnvil.ts
  4. 15
      striker-ui/lib/Anvil/handleAPIGetOneAnvil.ts

@ -0,0 +1,22 @@
import { NextApiHandler, NextApiRequest, NextApiResponse } from 'next';
const handleAPIFakeGetAllAnvil: NextApiHandler<AnvilList> = (
request: NextApiRequest,
response: NextApiResponse<AnvilList>,
): void => {
response.send({
anvils: [
{
uuid: '62ed925e-dddc-4541-acae-525fc99a9945',
},
{
uuid: '1040f37a-9847-4025-af2e-973b0f136979',
},
{
uuid: '52057dd0-04a6-4097-8a38-deb036116190',
},
],
});
};
export default handleAPIFakeGetAllAnvil;

@ -0,0 +1,23 @@
import { NextApiHandler, NextApiRequest, NextApiResponse } from 'next';
const handleAPIFakeGetOneAnvil: NextApiHandler<AnvilStatus> = (
request: NextApiRequest,
response: NextApiResponse<AnvilStatus>,
): void => {
const generateNodeState: () => 0 | 1 = (): 0 | 1 =>
Math.random() > 0.5 ? 1 : 0;
response.send({
nodes: [
{
on: generateNodeState(),
},
{
on: generateNodeState(),
},
],
timestamp: Math.round(Date.now() / 1000),
});
};
export default handleAPIFakeGetOneAnvil;

@ -1,11 +1,12 @@
import { NextApiRequest, NextApiResponse } from 'next';
import { NextApiHandler, NextApiRequest, NextApiResponse } from 'next';
import getAllAnvil from './getAllAnvil';
import handleAPIFakeGetAllAnvil from './handleAPIFakeGetAllAnvil';
async function handleAPIGetAllAnvil(
const handleAPIGetAllAnvil: NextApiHandler<AnvilList> = async (
request: NextApiRequest,
response: NextApiResponse,
): Promise<void> {
response: NextApiResponse<AnvilList>,
): Promise<void> => {
const { anvilList, error }: GetAllAnvilResponse = await getAllAnvil();
if (error) {
@ -15,6 +16,8 @@ async function handleAPIGetAllAnvil(
}
response.send(anvilList);
}
};
export default handleAPIGetAllAnvil;
export default process.env.IS_USE_FAKE_DATA
? handleAPIFakeGetAllAnvil
: handleAPIGetAllAnvil;

@ -1,11 +1,12 @@
import { NextApiRequest, NextApiResponse } from 'next';
import { NextApiHandler, NextApiRequest, NextApiResponse } from 'next';
import getOneAnvil from './getOneAnvil';
import handleAPIFakeGetOneAnvil from './handleAPIFakeGetOneAnvil';
async function handleAPIGetOneAnvil(
const handleAPIGetOneAnvil: NextApiHandler<AnvilStatus> = async (
request: NextApiRequest,
response: NextApiResponse,
): Promise<void> {
response: NextApiResponse<AnvilStatus>,
): Promise<void> => {
const {
query: { uuid },
}: NextApiRequest = request;
@ -23,6 +24,8 @@ async function handleAPIGetOneAnvil(
}
response.send(anvilStatus);
}
};
export default handleAPIGetOneAnvil;
export default process.env.IS_USE_FAKE_DATA
? handleAPIFakeGetOneAnvil
: handleAPIGetOneAnvil;

Loading…
Cancel
Save