mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-02-23 14:39:32 +08:00
fix(graphql): fix dates in google sheet transform types
This commit is contained in:
parent
7201a4f351
commit
c842f7e712
1
.pnp.js
generated
1
.pnp.js
generated
@ -3813,6 +3813,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
|
||||
["graphql-type-json", "virtual:7fa6405098723f150ab741c1e73c906de11a676b4cc641bac8b3397ea2dd6efbb913e72a780932220533241b442cc586b41b26c7b5ac786de486992cd2db054c#npm:0.3.2"],
|
||||
["jest", "npm:26.6.3"],
|
||||
["mingo", "npm:3.1.0"],
|
||||
["moment", "npm:2.29.1"],
|
||||
["mongodb", "virtual:7fa6405098723f150ab741c1e73c906de11a676b4cc641bac8b3397ea2dd6efbb913e72a780932220533241b442cc586b41b26c7b5ac786de486992cd2db054c#npm:3.6.3"],
|
||||
["webpack", "virtual:7fa6405098723f150ab741c1e73c906de11a676b4cc641bac8b3397ea2dd6efbb913e72a780932220533241b442cc586b41b26c7b5ac786de486992cd2db054c#npm:5.4.0"],
|
||||
["webpack-cli", "virtual:7fa6405098723f150ab741c1e73c906de11a676b4cc641bac8b3397ea2dd6efbb913e72a780932220533241b442cc586b41b26c7b5ac786de486992cd2db054c#npm:4.2.0"]
|
||||
|
@ -52,6 +52,7 @@
|
||||
"graphql": "15.4.0",
|
||||
"graphql-type-json": "0.3.2",
|
||||
"mingo": "3.1.0",
|
||||
"moment": "2.29.1",
|
||||
"mongodb": "3.6.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -266,7 +266,7 @@ test('googleSheetGetMany, columnTypes', async () => {
|
||||
id: '1',
|
||||
name: 'John',
|
||||
age: 34,
|
||||
birth_date: new Date('2020/04/26'),
|
||||
birth_date: new Date('2020-04-26T00:00:00.000Z'),
|
||||
married: true,
|
||||
},
|
||||
{
|
||||
@ -275,7 +275,7 @@ test('googleSheetGetMany, columnTypes', async () => {
|
||||
id: '2',
|
||||
name: 'Steve',
|
||||
age: 43,
|
||||
birth_date: new Date('2020/04/27'),
|
||||
birth_date: new Date('2020-04-27T00:00:00.000Z'),
|
||||
married: false,
|
||||
},
|
||||
{
|
||||
@ -284,7 +284,7 @@ test('googleSheetGetMany, columnTypes', async () => {
|
||||
id: '3',
|
||||
name: 'Tim',
|
||||
age: 34,
|
||||
birth_date: new Date('2020/04/28'),
|
||||
birth_date: new Date('2020-04-28T00:00:00.000Z'),
|
||||
married: false,
|
||||
},
|
||||
{
|
||||
|
@ -211,7 +211,7 @@ test('googleSheetGetOne, columnTypes', async () => {
|
||||
id: '1',
|
||||
name: 'John',
|
||||
age: 34,
|
||||
birth_date: new Date('2020/04/26'),
|
||||
birth_date: new Date('2020-04-26T00:00:00.000Z'),
|
||||
married: true,
|
||||
});
|
||||
});
|
||||
|
@ -27,13 +27,7 @@ async function authenticate({ doc, apiKey, client_email, private_key }) {
|
||||
}
|
||||
}
|
||||
|
||||
async function getSheet({ connection }) {
|
||||
const { apiKey, client_email, private_key, sheetId, sheetIndex, spreadsheetId } = connection;
|
||||
const doc = new GoogleSpreadsheet(spreadsheetId);
|
||||
|
||||
await authenticate({ doc, apiKey, client_email, private_key });
|
||||
|
||||
await doc.loadInfo();
|
||||
function getSheetFromDoc({ doc, sheetId, sheetIndex }) {
|
||||
let sheet;
|
||||
if (sheetId) {
|
||||
sheet = doc.sheetsById[sheetId];
|
||||
@ -49,4 +43,15 @@ async function getSheet({ connection }) {
|
||||
return sheet;
|
||||
}
|
||||
|
||||
async function getSheet({ connection }) {
|
||||
const { apiKey, client_email, private_key, sheetId, sheetIndex, spreadsheetId } = connection;
|
||||
const doc = new GoogleSpreadsheet(spreadsheetId);
|
||||
|
||||
await authenticate({ doc, apiKey, client_email, private_key });
|
||||
|
||||
await doc.loadInfo();
|
||||
|
||||
return getSheetFromDoc({ doc, sheetId, sheetIndex });
|
||||
}
|
||||
|
||||
export default getSheet;
|
||||
|
@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
import { type } from '@lowdefy/helpers';
|
||||
import moment from 'moment';
|
||||
|
||||
const readTransformers = {
|
||||
string: (value) => value,
|
||||
@ -25,9 +26,9 @@ const readTransformers = {
|
||||
},
|
||||
boolean: (value) => value === 'TRUE',
|
||||
date: (value) => {
|
||||
const date = new Date(value);
|
||||
if (isNaN(date.getTime())) return null;
|
||||
return date;
|
||||
const date = moment.utc(value);
|
||||
if (!date.isValid()) return null;
|
||||
return date.toDate();
|
||||
},
|
||||
json: (value) => {
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user