Fixes linter issues and adds Github action

This commit is contained in:
Chris Anderson 2022-08-16 16:51:48 -05:00
parent acc4701e5e
commit 7426dbd81d
12 changed files with 49 additions and 37 deletions

View file

@ -19,6 +19,7 @@
"rules": {
"indent": ["error", 4],
"padded-blocks": "off",
"camelcase": "off",
"no-use-before-define": "off",
"comma-dangle": "off",
"space-before-function-paren": ["error", {

23
.github/workflows/test.yml vendored Normal file
View file

@ -0,0 +1,23 @@
name: Build
on:
pull_request:
jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Node Install
run: |
npm install
- name: Lint
run: |
npm run lint

2
global.d.ts vendored
View file

@ -1,3 +1,3 @@
declare module 'handlebars-utils' {
export function value(val: any, context: any, options: any)
}
}

View file

@ -1,7 +1,5 @@
import App from "../app";
import { Job } from "../queue";
import App from '../app'
import { Job } from '../queue'
interface UserDeleteTrigger {
project_id: number
@ -11,7 +9,7 @@ interface UserDeleteTrigger {
export default class UserDeleteJob extends Job {
static $name = 'user_delete'
static from (data: UserDeleteTrigger): UserDeleteJob {
static from(data: UserDeleteTrigger): UserDeleteJob {
return new this(data)
}

View file

@ -1,7 +1,7 @@
import App from "../app";
import { User } from "../models/User";
import { ClientPatchUser } from "../models/client";
import { Job } from "../queue";
import App from '../app'
import { User } from '../models/User'
import { ClientPatchUser } from '../models/client'
import { Job } from '../queue'
interface UserPatchTrigger {
project_id: number
@ -11,25 +11,25 @@ interface UserPatchTrigger {
export default class UserPatchJob extends Job {
static $name = 'user_patch'
static from (data: UserPatchTrigger): UserPatchJob {
static from(data: UserPatchTrigger): UserPatchJob {
return new this(data)
}
static async handler({ project_id, user: { external_id, data, ...fields } }: UserPatchTrigger) {
await App.main.db.transaction(async trx => {
const existing = await trx('users')
.where('project_id', project_id)
.where('external_id', external_id)
.first()
.then(r => new User(r))
.then(r => User.fromJson(r))
if (existing) {
await trx('users')
.update({
data: data ? JSON.stringify({ ...existing.data, ...data }) : undefined,
...fields
...fields,
})
.where({ external_id })
} else {
@ -38,12 +38,9 @@ export default class UserPatchJob extends Job {
project_id,
external_id,
data: JSON.stringify(data),
...fields
...fields,
})
}
})
}
}

View file

@ -91,9 +91,3 @@ export default class Model {
return db(this.tableName)
}
}
export const firstModel = async <T extends new (json: any) => T>(Model: T, promise: Promise<any>): Promise<T | undefined> => {
const response = await promise
if (!response) return response
return new Model(response)
}

View file

@ -1,4 +1,4 @@
import type { User } from "./User"
import type { User } from './User'
export type ClientPatchUser = Pick<User, 'external_id'> & Partial<Pick<User, 'email' | 'phone' | 'data'>>

View file

@ -55,6 +55,7 @@ export default class Queue {
console.log('started', job)
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async errored(job: EncodedJob, error: Error) {
// TODO: Do something about failure
}

View file

@ -1,5 +1,5 @@
import type { JSONSchemaType } from "ajv";
import type { ClientDeleteUsersRequest, ClientPatchUsersRequest, ClientPostEventsRequest } from "models/client";
import type { JSONSchemaType } from 'ajv'
import type { ClientDeleteUsersRequest, ClientPatchUsersRequest, ClientPostEventsRequest } from 'models/client'
export const patchUsersRequest: JSONSchemaType<ClientPatchUsersRequest> = {
type: 'array',
@ -21,9 +21,9 @@ export const patchUsersRequest: JSONSchemaType<ClientPatchUsersRequest> = {
data: {
type: 'object',
nullable: true,
additionalProperties: true
}
}
additionalProperties: true,
},
},
},
minItems: 1,
}
@ -31,7 +31,7 @@ export const patchUsersRequest: JSONSchemaType<ClientPatchUsersRequest> = {
export const deleteUsersRequest: JSONSchemaType<ClientDeleteUsersRequest> = {
type: 'array',
items: {
type: 'string'
type: 'string',
},
minItems: 1,
}
@ -52,8 +52,8 @@ export const postEventsRequest: JSONSchemaType<ClientPostEventsRequest> = {
type: 'object',
nullable: true,
additionalProperties: true,
}
}
},
},
},
minItems: 1,
}

View file

@ -19,8 +19,6 @@ export default class JourneyService {
while (nextStep) {
const parsedStep = this.parse(nextStep)
console.log('run', nextStep.id)
// If completed, jump to next otherwise validate condition
if (await parsedStep.hasCompleted(user)) {
nextStep = await parsedStep.next(user)

View file

@ -3,7 +3,7 @@ import { User } from '../../../models/User'
import Journey from '../Journey'
import { lastJourneyStep } from '../JourneyRepository'
import JourneyService from '../JourneyService'
import { JourneyEntrance, JourneyMap, JourneyUserStep } from '../JourneyStep'
import { JourneyEntrance, JourneyMap } from '../JourneyStep'
describe('Run', () => {
describe('step progression', () => {

View file

@ -1,5 +1,5 @@
import { User } from '../../../models/User'
import { JourneyStep, JourneyEntrance, JourneyGate, JourneyMap } from '../JourneyStep'
import { JourneyStep, JourneyEntrance, JourneyMap } from '../JourneyStep'
describe('JourneyEntrance', () => {
describe('user entrance', () => {