Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
wensihao123 committed Aug 30, 2019
1 parent 5e801dd commit 785e415
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
7 changes: 1 addition & 6 deletions src/DynamoUtil.test.ts
Expand Up @@ -1825,14 +1825,13 @@ const boundaries2 = {
};

test('getInlineWarrantBoundaries', async () => {
DynamoUtil.getLocalTodayString = jest.fn(() => '2019-01-01');
dynamoUtil.queryData = jest.fn(() =>
Promise.resolve({
Count: 1,
Items: [boundaries as any, boundaries2 as any]
})
);
expect(await dynamoUtil.getInlineWarrantBoundaries()).toMatchSnapshot();
expect(await dynamoUtil.getInlineWarrantBoundaries('2019-02-02')).toMatchSnapshot();
});

test('getUTCNowTimestamp', () => {
Expand All @@ -1842,7 +1841,3 @@ test('getUTCNowTimestamp', () => {
test('getUTCNowDateString', () => {
expect(DynamoUtil.getUTCNowDateString()).toHaveLength(10);
})

test('getLocalTodayString', () => {
expect(DynamoUtil.getLocalTodayString()).toHaveLength(10);
})
22 changes: 9 additions & 13 deletions src/DynamoUtil.ts
Expand Up @@ -801,22 +801,22 @@ export class DynamoUtil {
await this.insertData(params);
}

public async getInlineWarrantBoundaries() {
public async getInlineWarrantBoundaries(date: string) {
const params = {
TableName: this.live ? CST.BOUNDARIESTABLE : CST.BOUNDARIESTABLEKOVAN,
KeyConditionExpression: `${CST.DB_TX_QTEBASE} = :${CST.DB_TX_QTEBASE}`,
KeyConditionExpression: `${CST.DB_TX_QTEBASE} = :${CST.DB_TX_QTEBASE} AND #${CST.DB_DATE} = :${CST.DB_DATE}`,
ExpressionAttributeNames: {
[`#${CST.DB_DATE}`]: CST.DB_DATE
},
ExpressionAttributeValues: {
[`:${CST.DB_TX_QTEBASE}`]: { S: `${CST.DB_ETHUSD}` }
[`:${CST.DB_TX_QTEBASE}`]: { S: `${CST.DB_ETHUSD}` },
[`:${CST.DB_DATE}`]: { S: date }
}
};
const data = await this.queryData(params);
let boundaries = [0, 0];
if (data.Count)
(data.Items as any).forEach((item: any) => {
if (item.date.S === DynamoUtil.getLocalTodayString())
boundaries = [Number(item.ub.S), Number(item.lb.S)];
});

boundaries = [Number((data.Items as any)[0].ub.S), Number((data.Items as any)[0].lb.S)];
return boundaries;
}

Expand All @@ -833,11 +833,7 @@ export class DynamoUtil {
}

public static getUTCNowDateString() {
return moment.utc().format('YYYY-MM-DD')
}

public static getLocalTodayString() {
return moment().format('YYYY-MM-DD')
return moment.utc().format('YYYY-MM-DD');
}
}

Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Expand Up @@ -75,6 +75,7 @@ export const DB_STATUS_EVENT_PUBLIC_OTHERS = 'EVENT_AWS_PUBLIC_OTHERS';
export const DB_ADDRESS = 'address';
export const DB_ETHUSD = 'ETH|USD';
export const DB_PENDING = 'pending';
export const DB_DATE = 'date';
export const WARRENTTABLE = 'duo.live.warrant';
export const WARRENTTABLEKOVAN = 'duo.dev.warrant';
export const BOUNDARIESTABLE = 'duo.live.boundaries';
Expand Down

0 comments on commit 785e415

Please sign in to comment.