Skip to content

Commit 2e17da9

Browse files
chore: wip
1 parent ae3c623 commit 2e17da9

File tree

11 files changed

+272
-7
lines changed

11 files changed

+272
-7
lines changed

app/Middleware/Api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ export default new Middleware({
1919

2020
const team = await Team.find(Number(teamToken))
2121

22-
if (! team) {
22+
if (!team) {
2323
throw { message: 'Invalid bearer token', status: 401 }
2424
}
2525

2626
const teamBearerToken = await AccessToken.where('token', plainString).first()
2727

28-
if (! teamBearerToken) {
28+
if (!teamBearerToken) {
2929
throw { message: 'Invalid bearer token', status: 401 }
3030
}
3131
},

storage/framework/core/actions/src/orm/generate-model.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { log } from '@stacksjs/logging'
22
import { getModelName, getTableName } from '@stacksjs/orm'
33
import { path } from '@stacksjs/path'
44
import { fs, glob } from '@stacksjs/storage'
5-
import { camelCase, pascalCase, plural } from '@stacksjs/strings'
5+
import { camelCase, capitalCase, pascalCase, plural } from '@stacksjs/strings'
66
import type { Model, RelationConfig } from '@stacksjs/types'
77
import { isString } from '@stacksjs/validation'
88
export interface FieldArrayElement {
@@ -635,6 +635,7 @@ async function generateModelString(
635635
let fieldString = ''
636636
let constructorFields = ''
637637
let declareFields = ''
638+
let whereStatements = ''
638639
let relationMethods = ``
639640
let relationImports = ``
640641

@@ -768,6 +769,14 @@ async function generateModelString(
768769
declareFields += `public ${attribute.field}: ${entity} | undefined \n `
769770

770771
constructorFields += `this.${attribute.field} = ${formattedModelName}?.${attribute.field}\n `
772+
773+
whereStatements += `static where${pascalCase(attribute.field)}(value: string | number | boolean): ${modelName}Model {
774+
const instance = new this(null);
775+
776+
instance.query = instance.query.where('${attribute.field}', '=', value)
777+
778+
return instance
779+
} \n\n`
771780
}
772781

773782
const otherModelRelations = await fetchOtherModelRelations(model, modelName)
@@ -1029,6 +1038,8 @@ async function generateModelString(
10291038
return instance
10301039
}
10311040
1041+
${whereStatements}
1042+
10321043
static whereIn(column: keyof ${modelName}Type, values: any[]): ${modelName}Model {
10331044
const instance = new this(null);
10341045
@@ -1103,7 +1114,7 @@ async function generateModelString(
11031114
if (this.id === undefined)
11041115
throw new Error('${modelName} ID is undefined')
11051116
1106-
const updatedModel = await db.updateTable('${tableName}')
1117+
await db.updateTable('${tableName}')
11071118
.set(${formattedModelName})
11081119
.where('id', '=', this.id)
11091120
.executeTakeFirst()

storage/framework/orm/src/models/AccessToken.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,38 @@ export class AccessTokenModel {
230230
return this
231231
}
232232

233+
static whereName(value: string | number | boolean): AccessTokenModel {
234+
const instance = new this(null)
235+
236+
instance.query = instance.query.where('name', '=', value)
237+
238+
return instance
239+
}
240+
241+
static whereToken(value: string | number | boolean): AccessTokenModel {
242+
const instance = new this(null)
243+
244+
instance.query = instance.query.where('token', '=', value)
245+
246+
return instance
247+
}
248+
249+
static wherePlainTextToken(value: string | number | boolean): AccessTokenModel {
250+
const instance = new this(null)
251+
252+
instance.query = instance.query.where('plainTextToken', '=', value)
253+
254+
return instance
255+
}
256+
257+
static whereAbilities(value: string | number | boolean): AccessTokenModel {
258+
const instance = new this(null)
259+
260+
instance.query = instance.query.where('abilities', '=', value)
261+
262+
return instance
263+
}
264+
233265
static where(...args: (string | number)[]): AccessTokenModel {
234266
let column: any
235267
let operator: any

storage/framework/orm/src/models/Deployment.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,62 @@ export class DeploymentModel {
238238
return this
239239
}
240240

241+
static whereCommitSha(value: string | number | boolean): DeploymentModel {
242+
const instance = new this(null)
243+
244+
instance.query = instance.query.where('commitSha', '=', value)
245+
246+
return instance
247+
}
248+
249+
static whereCommitMessage(value: string | number | boolean): DeploymentModel {
250+
const instance = new this(null)
251+
252+
instance.query = instance.query.where('commitMessage', '=', value)
253+
254+
return instance
255+
}
256+
257+
static whereBranch(value: string | number | boolean): DeploymentModel {
258+
const instance = new this(null)
259+
260+
instance.query = instance.query.where('branch', '=', value)
261+
262+
return instance
263+
}
264+
265+
static whereStatus(value: string | number | boolean): DeploymentModel {
266+
const instance = new this(null)
267+
268+
instance.query = instance.query.where('status', '=', value)
269+
270+
return instance
271+
}
272+
273+
static whereExecutionTime(value: string | number | boolean): DeploymentModel {
274+
const instance = new this(null)
275+
276+
instance.query = instance.query.where('executionTime', '=', value)
277+
278+
return instance
279+
}
280+
281+
static whereDeployScript(value: string | number | boolean): DeploymentModel {
282+
const instance = new this(null)
283+
284+
instance.query = instance.query.where('deployScript', '=', value)
285+
286+
return instance
287+
}
288+
289+
static whereTerminalOutput(value: string | number | boolean): DeploymentModel {
290+
const instance = new this(null)
291+
292+
instance.query = instance.query.where('terminalOutput', '=', value)
293+
294+
return instance
295+
}
296+
241297
static where(...args: (string | number)[]): DeploymentModel {
242298
let column: any
243299
let operator: any

storage/framework/orm/src/models/Post.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,22 @@ export class PostModel {
223223
return this
224224
}
225225

226+
static whereTitle(value: string | number | boolean): PostModel {
227+
const instance = new this(null)
228+
229+
instance.query = instance.query.where('title', '=', value)
230+
231+
return instance
232+
}
233+
234+
static whereBody(value: string | number | boolean): PostModel {
235+
const instance = new this(null)
236+
237+
instance.query = instance.query.where('body', '=', value)
238+
239+
return instance
240+
}
241+
226242
static where(...args: (string | number)[]): PostModel {
227243
let column: any
228244
let operator: any

storage/framework/orm/src/models/Project.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,38 @@ export class ProjectModel {
225225
return this
226226
}
227227

228+
static whereName(value: string | number | boolean): ProjectModel {
229+
const instance = new this(null)
230+
231+
instance.query = instance.query.where('name', '=', value)
232+
233+
return instance
234+
}
235+
236+
static whereDescription(value: string | number | boolean): ProjectModel {
237+
const instance = new this(null)
238+
239+
instance.query = instance.query.where('description', '=', value)
240+
241+
return instance
242+
}
243+
244+
static whereUrl(value: string | number | boolean): ProjectModel {
245+
const instance = new this(null)
246+
247+
instance.query = instance.query.where('url', '=', value)
248+
249+
return instance
250+
}
251+
252+
static whereStatus(value: string | number | boolean): ProjectModel {
253+
const instance = new this(null)
254+
255+
instance.query = instance.query.where('status', '=', value)
256+
257+
return instance
258+
}
259+
228260
static where(...args: (string | number)[]): ProjectModel {
229261
let column: any
230262
let operator: any

storage/framework/orm/src/models/Release.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,14 @@ export class ReleaseModel {
216216
return this
217217
}
218218

219+
static whereVersion(value: string | number | boolean): ReleaseModel {
220+
const instance = new this(null)
221+
222+
instance.query = instance.query.where('version', '=', value)
223+
224+
return instance
225+
}
226+
219227
static where(...args: (string | number)[]): ReleaseModel {
220228
let column: any
221229
let operator: any

storage/framework/orm/src/models/Subscriber.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,14 @@ export class SubscriberModel {
219219
return this
220220
}
221221

222+
static whereSubscribed(value: string | number | boolean): SubscriberModel {
223+
const instance = new this(null)
224+
225+
instance.query = instance.query.where('subscribed', '=', value)
226+
227+
return instance
228+
}
229+
222230
static where(...args: (string | number)[]): SubscriberModel {
223231
let column: any
224232
let operator: any

storage/framework/orm/src/models/SubscriberEmail.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,14 @@ export class SubscriberEmailModel {
219219
return this
220220
}
221221

222+
static whereEmail(value: string | number | boolean): SubscriberEmailModel {
223+
const instance = new this(null)
224+
225+
instance.query = instance.query.where('email', '=', value)
226+
227+
return instance
228+
}
229+
222230
static where(...args: (string | number)[]): SubscriberEmailModel {
223231
let column: any
224232
let operator: any

storage/framework/orm/src/models/Team.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,70 @@ export class TeamModel {
241241
return this
242242
}
243243

244+
static whereName(value: string | number | boolean): TeamModel {
245+
const instance = new this(null)
246+
247+
instance.query = instance.query.where('name', '=', value)
248+
249+
return instance
250+
}
251+
252+
static whereCompanyName(value: string | number | boolean): TeamModel {
253+
const instance = new this(null)
254+
255+
instance.query = instance.query.where('companyName', '=', value)
256+
257+
return instance
258+
}
259+
260+
static whereEmail(value: string | number | boolean): TeamModel {
261+
const instance = new this(null)
262+
263+
instance.query = instance.query.where('email', '=', value)
264+
265+
return instance
266+
}
267+
268+
static whereBillingEmail(value: string | number | boolean): TeamModel {
269+
const instance = new this(null)
270+
271+
instance.query = instance.query.where('billingEmail', '=', value)
272+
273+
return instance
274+
}
275+
276+
static whereStatus(value: string | number | boolean): TeamModel {
277+
const instance = new this(null)
278+
279+
instance.query = instance.query.where('status', '=', value)
280+
281+
return instance
282+
}
283+
284+
static whereDescription(value: string | number | boolean): TeamModel {
285+
const instance = new this(null)
286+
287+
instance.query = instance.query.where('description', '=', value)
288+
289+
return instance
290+
}
291+
292+
static wherePath(value: string | number | boolean): TeamModel {
293+
const instance = new this(null)
294+
295+
instance.query = instance.query.where('path', '=', value)
296+
297+
return instance
298+
}
299+
300+
static whereIsPersonal(value: string | number | boolean): TeamModel {
301+
const instance = new this(null)
302+
303+
instance.query = instance.query.where('isPersonal', '=', value)
304+
305+
return instance
306+
}
307+
244308
static where(...args: (string | number)[]): TeamModel {
245309
let column: any
246310
let operator: any

0 commit comments

Comments
 (0)