Skip to content

Commit

Permalink
fix versions
Browse files Browse the repository at this point in the history
  • Loading branch information
yorkie committed May 20, 2020
1 parent 98e99b5 commit b98316a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/daemon/package.json
Expand Up @@ -46,7 +46,7 @@
"dev": "ts-node src/utils/dbinit.ts && cross-env NODE_ENV=local midway-bin dev --port=6927 --ts",
"debug": "cross-env NODE_ENV=local midway-bin debug --ts",
"cov": "midway-bin cov --ts",
"lint": "tslint --fix -p tsconfig.json -t stylish",
"lint": "tslint -p tsconfig.json -t stylish",
"ci": "npm run cov",
"compile": "midway-bin build -c --port=6927",
"clean": "rm -rf src/app/public"
Expand Down
12 changes: 6 additions & 6 deletions packages/daemon/src/model/job.ts
Expand Up @@ -12,7 +12,7 @@ providerWrapper([
export class JobModel extends Model {
readonly id: string;
readonly pipelineId: string;
readonly coreVersion: string;
readonly specVersion: string;
readonly status: number;
readonly metadata: number;
readonly evaluateMap: string;
Expand All @@ -24,11 +24,11 @@ export class JobModel extends Model {

export type JobModelStatic = typeof Model & {
new (values?: object, options?: BuildOptions): JobModel;
}
};

export default async function model(context: IApplicationContext): Promise<JobModelStatic> {
const db = await context.getAsync('pipcookDB') as DB;
const JobModel = <JobModelStatic>db.sequelize.define('job', {
const JobModel = db.sequelize.define('job', {
id: {
type: STRING,
primaryKey: true,
Expand All @@ -42,9 +42,9 @@ export default async function model(context: IApplicationContext): Promise<JobMo
key: 'id'
}
},
coreVersion: {
specVersion: {
type: STRING,
field: 'core_version',
field: 'spec_version',
allowNull: false
},
status: {
Expand Down Expand Up @@ -72,7 +72,7 @@ export default async function model(context: IApplicationContext): Promise<JobMo
endTime: {
type: INTEGER
}
});
}) as JobModelStatic;
await JobModel.sync();
return JobModel;
}
6 changes: 3 additions & 3 deletions packages/daemon/src/model/pipeline.ts
Expand Up @@ -31,12 +31,12 @@ export class PipelineModel extends Model {

export type PipelineModelStatic = typeof Model & {
new (values?: object, options?: BuildOptions): PipelineModel;
}
};

export default async function model(context: IApplicationContext): Promise<PipelineModelStatic> {
const db = await context.getAsync('pipcookDB') as DB;
const JobModel = await context.getAsync('jobModel') as JobModelStatic;
const PipelineModel = <PipelineModelStatic>db.sequelize.define('pipeline', {
const PipelineModel = db.sequelize.define('pipeline', {
id: {
type: STRING,
primaryKey: true,
Expand Down Expand Up @@ -89,7 +89,7 @@ export default async function model(context: IApplicationContext): Promise<Pipel
modelEvaluateParams: {
type: STRING
}
});
}) as PipelineModelStatic;
PipelineModel.hasMany(JobModel);
await PipelineModel.sync();
return PipelineModel;
Expand Down
18 changes: 10 additions & 8 deletions packages/daemon/src/service/pipeline.ts
Expand Up @@ -35,16 +35,18 @@ export class PipelineService {
}

async getPipelineById(id: string): Promise<PipelineModel> {
return await this.model.findOne({
return this.model.findOne({
where: getIdOrName(id)
});
}

async getPipelines(offset: number, limit: number): Promise<{rows: PipelineModel[], count: number}> {
return await this.model.findAndCountAll({
return this.model.findAndCountAll({
offset,
limit,
order: [ [ 'createdAt', 'DESC' ] ]
order: [
[ 'createdAt', 'DESC' ]
]
});
}

Expand All @@ -58,10 +60,10 @@ export class PipelineService {
await this.model.update(config, {
where: getIdOrName(id)
});
return await this.getPipelineById(id);
return this.getPipelineById(id);
}

async createNewRun(pipelineId: string): Promise<JobModel> {
async createJob(pipelineId: string): Promise<JobModel> {
pipelineId = await this.getPipelineId(pipelineId);
const config = await createRun(pipelineId);
const record = await this.job.create(config);
Expand All @@ -71,14 +73,14 @@ export class PipelineService {
}

async getJobById(id: string): Promise<JobModel> {
return await this.job.findOne({
return this.job.findOne({
where: { id }
});
}

async getJobsByPipelineId(id: string, offset: number, limit: number): Promise<{rows: JobModel[], count: number}> {
const pipelineId = await this.getPipelineId(id);
return await this.job.findAndCountAll({
return this.job.findAndCountAll({
offset,
limit,
where: {
Expand All @@ -91,7 +93,7 @@ export class PipelineService {
}

async getJobs(offset: number, limit: number): Promise<{rows: JobModel[], count: number}> {
return await this.job.findAndCountAll({
return this.job.findAndCountAll({
offset,
limit,
order: [
Expand Down
3 changes: 2 additions & 1 deletion packages/daemon/tslint.json
Expand Up @@ -4,6 +4,7 @@
],
"rules": {
"no-unused-expression": false,
"no-bitwise": false
"no-bitwise": false,
"callable-types": false
}
}

0 comments on commit b98316a

Please sign in to comment.