Merge pull request #366 from automatisch/feature/connection-draft-column
feat: Add draft column to connections
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
import { Knex } from 'knex';
|
||||
|
||||
export async function up(knex: Knex): Promise<void> {
|
||||
return knex.schema.table('connections', (table) => {
|
||||
table.boolean('draft').defaultTo(true);
|
||||
});
|
||||
}
|
||||
|
||||
export async function down(knex: Knex): Promise<void> {
|
||||
return knex.schema.table('connections', (table) => {
|
||||
table.dropColumn('draft');
|
||||
});
|
||||
}
|
@@ -13,19 +13,12 @@ const createConnection = async (
|
||||
params: Params,
|
||||
context: Context
|
||||
) => {
|
||||
const app = App.findOneByKey(params.input.key);
|
||||
App.findOneByKey(params.input.key);
|
||||
|
||||
const connection = await context.currentUser
|
||||
.$relatedQuery('connections')
|
||||
.insert({
|
||||
key: params.input.key,
|
||||
formattedData: params.input.formattedData,
|
||||
});
|
||||
|
||||
return {
|
||||
...connection,
|
||||
app,
|
||||
};
|
||||
return await context.currentUser.$relatedQuery('connections').insert({
|
||||
key: params.input.key,
|
||||
formattedData: params.input.formattedData,
|
||||
});
|
||||
};
|
||||
|
||||
export default createConnection;
|
||||
|
@@ -20,9 +20,9 @@ const verifyConnection = async (
|
||||
.throwIfNotFound();
|
||||
|
||||
const appClass = (await import(`../../apps/${connection.key}`)).default;
|
||||
const appData = App.findOneByKey(connection.key);
|
||||
const app = App.findOneByKey(connection.key);
|
||||
|
||||
const appInstance = new appClass(appData, connection.formattedData);
|
||||
const appInstance = new appClass(app, connection.formattedData);
|
||||
const verifiedCredentials =
|
||||
await appInstance.authenticationClient.verifyCredentials();
|
||||
|
||||
@@ -32,9 +32,13 @@ const verifyConnection = async (
|
||||
...verifiedCredentials,
|
||||
},
|
||||
verified: true,
|
||||
draft: false,
|
||||
});
|
||||
|
||||
return connection;
|
||||
return {
|
||||
...connection,
|
||||
app,
|
||||
};
|
||||
};
|
||||
|
||||
export default verifyConnection;
|
||||
|
@@ -13,6 +13,7 @@ const getApp = async (_parent: unknown, params: Params, context: Context) => {
|
||||
.$relatedQuery('connections')
|
||||
.where({
|
||||
key: params.key,
|
||||
draft: false,
|
||||
})
|
||||
.orderBy('created_at', 'desc');
|
||||
|
||||
|
@@ -14,6 +14,7 @@ class Connection extends Base {
|
||||
formattedData?: IJSONObject;
|
||||
userId!: string;
|
||||
verified = false;
|
||||
draft: boolean;
|
||||
count?: number;
|
||||
|
||||
static tableName = 'connections';
|
||||
@@ -29,6 +30,7 @@ class Connection extends Base {
|
||||
formattedData: { type: 'object' },
|
||||
userId: { type: 'string', format: 'uuid' },
|
||||
verified: { type: 'boolean' },
|
||||
draft: { type: 'boolean' },
|
||||
},
|
||||
};
|
||||
|
||||
|
@@ -1,6 +1,10 @@
|
||||
import { InMemoryCache } from '@apollo/client';
|
||||
import offsetLimitPagination from './pagination';
|
||||
|
||||
interface IRef {
|
||||
__ref: string;
|
||||
}
|
||||
|
||||
const cache = new InMemoryCache({
|
||||
typePolicies: {
|
||||
App: {
|
||||
@@ -9,9 +13,9 @@ const cache = new InMemoryCache({
|
||||
Mutation: {
|
||||
mutationType: true,
|
||||
fields: {
|
||||
createConnection: {
|
||||
merge(existing, newConnection, { readField, cache }) {
|
||||
const appKey = readField('key', newConnection);
|
||||
verifyConnection: {
|
||||
merge(existing, verifiedConnection, { readField, cache }) {
|
||||
const appKey = readField('key', verifiedConnection);
|
||||
const appCacheId = cache.identify({
|
||||
__typename: 'App',
|
||||
key: appKey,
|
||||
@@ -21,12 +25,22 @@ const cache = new InMemoryCache({
|
||||
id: appCacheId,
|
||||
fields: {
|
||||
connections: (existingConnections) => {
|
||||
return [...existingConnections, newConnection];
|
||||
const existingConnectionIndex = existingConnections.findIndex((connection: IRef) => {
|
||||
return connection.__ref === verifiedConnection.__ref;
|
||||
});
|
||||
const connectionExists = existingConnectionIndex !== -1;
|
||||
|
||||
// newly created and verified connection
|
||||
if (!connectionExists) {
|
||||
return [verifiedConnection, ...existingConnections];
|
||||
}
|
||||
|
||||
return existingConnections;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return newConnection;
|
||||
return verifiedConnection;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -11,9 +11,6 @@ export const CREATE_CONNECTION = gql`
|
||||
formattedData {
|
||||
screenName
|
||||
}
|
||||
app {
|
||||
key
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
@@ -4,10 +4,15 @@ export const VERIFY_CONNECTION = gql`
|
||||
mutation VerifyConnection($input: VerifyConnectionInput) {
|
||||
verifyConnection(input: $input) {
|
||||
id
|
||||
key
|
||||
verified
|
||||
formattedData {
|
||||
screenName
|
||||
}
|
||||
createdAt
|
||||
app {
|
||||
key
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
Reference in New Issue
Block a user