chore: Rename credentials as connections
This commit is contained in:
@@ -4,18 +4,18 @@ import Field from '../../types/field';
|
||||
|
||||
export default class Twitter {
|
||||
client: any
|
||||
credentialsData: any
|
||||
connectionData: any
|
||||
appData: any
|
||||
|
||||
constructor(credentialsData: any) {
|
||||
constructor(connectionData: any) {
|
||||
this.client = new TwitterApi({
|
||||
appKey: credentialsData.consumerKey,
|
||||
appSecret: credentialsData.consumerSecret,
|
||||
accessToken: credentialsData.accessToken,
|
||||
accessSecret: credentialsData.accessSecret
|
||||
appKey: connectionData.consumerKey,
|
||||
appSecret: connectionData.consumerSecret,
|
||||
accessToken: connectionData.accessToken,
|
||||
accessSecret: connectionData.accessSecret
|
||||
});
|
||||
|
||||
this.credentialsData = credentialsData;
|
||||
this.connectionData = connectionData;
|
||||
this.appData = App.findOneByName('twitter');
|
||||
}
|
||||
|
||||
@@ -27,11 +27,11 @@ export default class Twitter {
|
||||
}
|
||||
|
||||
async verifyCredentials() {
|
||||
const verifiedCredentials = await this.client.login(this.credentialsData.oauthVerifier)
|
||||
const verifiedCredentials = await this.client.login(this.connectionData.oauthVerifier)
|
||||
|
||||
return {
|
||||
consumerKey: this.credentialsData.consumerKey,
|
||||
consumerSecret: this.credentialsData.consumerSecret,
|
||||
consumerKey: this.connectionData.consumerKey,
|
||||
consumerSecret: this.connectionData.consumerSecret,
|
||||
accessToken: verifiedCredentials.accessToken,
|
||||
accessSecret: verifiedCredentials.accessSecret,
|
||||
userId: verifiedCredentials.userId,
|
||||
|
@@ -47,7 +47,7 @@
|
||||
{
|
||||
"step": 1,
|
||||
"type": "mutation",
|
||||
"name": "createCredential",
|
||||
"name": "createConnection",
|
||||
"fields": [
|
||||
{
|
||||
"name": "key",
|
||||
@@ -76,7 +76,7 @@
|
||||
"fields": [
|
||||
{
|
||||
"name": "id",
|
||||
"value": "{createCredential.id}"
|
||||
"value": "{createConnection.id}"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -94,11 +94,11 @@
|
||||
{
|
||||
"step": 4,
|
||||
"type": "mutation",
|
||||
"name": "updateCredential",
|
||||
"name": "updateConnection",
|
||||
"fields": [
|
||||
{
|
||||
"name": "id",
|
||||
"value": "{createCredential.id}"
|
||||
"value": "{createConnection.id}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
|
@@ -0,0 +1,9 @@
|
||||
import { Knex } from "knex";
|
||||
|
||||
export async function up(knex: Knex): Promise<void> {
|
||||
return knex.schema.renameTable('credentials', 'connections');
|
||||
}
|
||||
|
||||
export async function down(knex: Knex): Promise<void> {
|
||||
return knex.schema.renameTable('connections', 'credentials');
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
import { GraphQLNonNull, GraphQLString } from 'graphql';
|
||||
import Credential from '../../models/credential';
|
||||
import Connection from '../../models/connection';
|
||||
import authLinkType from '../types/auth-link';
|
||||
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||
|
||||
@@ -7,19 +7,19 @@ type Params = {
|
||||
id: number,
|
||||
}
|
||||
const createAuthLinkResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||
const credential = await Credential.query().findOne({
|
||||
const connection = await Connection.query().findOne({
|
||||
user_id: req.currentUser.id,
|
||||
id: params.id
|
||||
})
|
||||
|
||||
const appClass = (await import(`../../apps/${credential.key}`)).default;
|
||||
const appClass = (await import(`../../apps/${connection.key}`)).default;
|
||||
|
||||
const appInstance = new appClass(credential.data)
|
||||
const appInstance = new appClass(connection.data)
|
||||
const authLink = await appInstance.createAuthLink();
|
||||
|
||||
await credential.$query().patch({
|
||||
await connection.$query().patch({
|
||||
data: {
|
||||
...credential.data,
|
||||
...connection.data,
|
||||
url: authLink.url,
|
||||
accessToken: authLink.oauth_token,
|
||||
accessSecret: authLink.oauth_token_secret,
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { GraphQLString, GraphQLNonNull } from 'graphql';
|
||||
import Credential from '../../models/credential';
|
||||
import credentialType from '../types/credential';
|
||||
import Connection from '../../models/connection';
|
||||
import connectionType from '../types/connection';
|
||||
import twitterCredentialInputType from '../types/twitter-credential-input';
|
||||
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||
|
||||
@@ -8,23 +8,23 @@ type Params = {
|
||||
key: string,
|
||||
data: object
|
||||
}
|
||||
const createCredentialResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||
const credential = await Credential.query().insert({
|
||||
const createConnectionResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||
const connection = await Connection.query().insert({
|
||||
key: params.key,
|
||||
data: params.data,
|
||||
userId: req.currentUser.id
|
||||
});
|
||||
|
||||
return credential;
|
||||
return connection;
|
||||
}
|
||||
|
||||
const createCredential = {
|
||||
type: credentialType,
|
||||
const createConnection = {
|
||||
type: connectionType,
|
||||
args: {
|
||||
key: { type: GraphQLNonNull(GraphQLString) },
|
||||
data: { type: GraphQLNonNull(twitterCredentialInputType) }
|
||||
},
|
||||
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => createCredentialResolver(params, req)
|
||||
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => createConnectionResolver(params, req)
|
||||
};
|
||||
|
||||
export default createCredential;
|
||||
export default createConnection;
|
@@ -1,6 +1,6 @@
|
||||
import { GraphQLString, GraphQLNonNull } from 'graphql';
|
||||
import Credential from '../../models/credential';
|
||||
import credentialType from '../types/credential';
|
||||
import Connection from '../../models/connection';
|
||||
import connectionType from '../types/connection';
|
||||
import twitterCredentialInputType from '../types/twitter-credential-input';
|
||||
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||
|
||||
@@ -8,38 +8,38 @@ type Params = {
|
||||
id: string,
|
||||
data: object
|
||||
}
|
||||
const updateCredentialResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||
let credential = await Credential.query().findOne({
|
||||
const updateConnectionResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||
let connection = await Connection.query().findOne({
|
||||
user_id: req.currentUser.id,
|
||||
id: params.id
|
||||
})
|
||||
|
||||
credential = await credential.$query().patchAndFetch({
|
||||
connection = await connection.$query().patchAndFetch({
|
||||
data: {
|
||||
...credential.data,
|
||||
...connection.data,
|
||||
...params.data
|
||||
}
|
||||
})
|
||||
|
||||
const appClass = (await import(`../../apps/${credential.key}`)).default;
|
||||
const appClass = (await import(`../../apps/${connection.key}`)).default;
|
||||
|
||||
const appInstance = new appClass(credential.data)
|
||||
const appInstance = new appClass(connection.data)
|
||||
const verifiedCredentials = await appInstance.verifyCredentials();
|
||||
|
||||
credential = await credential.$query().patchAndFetch({
|
||||
connection = await connection.$query().patchAndFetch({
|
||||
data: verifiedCredentials
|
||||
})
|
||||
|
||||
return credential;
|
||||
return connection;
|
||||
}
|
||||
|
||||
const updateCredential = {
|
||||
type: credentialType,
|
||||
const updateConnection = {
|
||||
type: connectionType,
|
||||
args: {
|
||||
id: { type: GraphQLNonNull(GraphQLString) },
|
||||
data: { type: GraphQLNonNull(twitterCredentialInputType) }
|
||||
},
|
||||
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => updateCredentialResolver(params, req)
|
||||
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => updateConnectionResolver(params, req)
|
||||
};
|
||||
|
||||
export default updateCredential;
|
||||
export default updateConnection;
|
@@ -1,14 +1,14 @@
|
||||
import { GraphQLObjectType } from 'graphql';
|
||||
import createCredential from './mutations/create-credential';
|
||||
import createConnection from './mutations/create-connection';
|
||||
import createAuthLink from './mutations/create-auth-link';
|
||||
import updateCredential from './mutations/update-credential';
|
||||
import updateConnection from './mutations/update-connection';
|
||||
|
||||
const rootMutation = new GraphQLObjectType({
|
||||
name: 'Mutation',
|
||||
fields: {
|
||||
createCredential: createCredential,
|
||||
createConnection: createConnection,
|
||||
createAuthLink: createAuthLink,
|
||||
updateCredential: updateCredential
|
||||
updateConnection: updateConnection
|
||||
}
|
||||
});
|
||||
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import { GraphQLObjectType, GraphQLString, GraphQLBoolean } from 'graphql';
|
||||
import twitterCredentialType from './twitter-credential';
|
||||
|
||||
const credentialType = new GraphQLObjectType({
|
||||
name: 'credential',
|
||||
const connectionType = new GraphQLObjectType({
|
||||
name: 'connection',
|
||||
fields: {
|
||||
id: { type: GraphQLString },
|
||||
key: { type: GraphQLString },
|
||||
@@ -11,4 +11,4 @@ const credentialType = new GraphQLObjectType({
|
||||
}
|
||||
})
|
||||
|
||||
export default credentialType;
|
||||
export default connectionType;
|
@@ -1,14 +1,14 @@
|
||||
import Base from './base'
|
||||
import User from './user'
|
||||
|
||||
class Credential extends Base {
|
||||
class Connection extends Base {
|
||||
id!: number
|
||||
key!: string
|
||||
data!: any
|
||||
userId!: number
|
||||
verified: boolean
|
||||
|
||||
static tableName = 'credentials';
|
||||
static tableName = 'connections';
|
||||
|
||||
static jsonSchema = {
|
||||
type: 'object',
|
||||
@@ -24,15 +24,15 @@ class Credential extends Base {
|
||||
}
|
||||
|
||||
static relationMappings = () => ({
|
||||
credentials: {
|
||||
user: {
|
||||
relation: Base.BelongsToOneRelation,
|
||||
modelClass: User,
|
||||
join: {
|
||||
from: 'credentials.user_id',
|
||||
from: 'connections.user_id',
|
||||
to: 'users.id',
|
||||
},
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export default Credential;
|
||||
export default Connection;
|
@@ -1,6 +1,6 @@
|
||||
import { QueryContext, ModelOptions } from 'objection';
|
||||
import Base from './base';
|
||||
import Credential from './credential';
|
||||
import Connection from './connection';
|
||||
import bcrypt from 'bcrypt';
|
||||
|
||||
class User extends Base {
|
||||
@@ -22,12 +22,12 @@ class User extends Base {
|
||||
}
|
||||
|
||||
static relationMappings = () => ({
|
||||
credentials: {
|
||||
connections: {
|
||||
relation: Base.HasManyRelation,
|
||||
modelClass: Credential,
|
||||
modelClass: Connection,
|
||||
join: {
|
||||
from: 'users.id',
|
||||
to: 'credentials.user_id',
|
||||
to: 'connections.user_id',
|
||||
},
|
||||
}
|
||||
})
|
||||
|
Reference in New Issue
Block a user