Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
glennmichael123 committed Feb 6, 2025
1 parent abbc171 commit c346937
Show file tree
Hide file tree
Showing 18 changed files with 234 additions and 162 deletions.
22 changes: 13 additions & 9 deletions storage/framework/core/orm/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1021,25 +1021,29 @@ export async function generateModelString(
return await instance.applyFirst()
}
async firstOrFail(): Promise<${modelName}Model | undefined> {
return await ${modelName}Model.firstOrFail()
}
static async firstOrFail(): Promise<${modelName}Model | undefined> {
const instance = new ${modelName}Model(null)
const model = await instance.selectFromQuery.executeTakeFirst()
async applyFirstOrFail(): Promise<${modelName}Model | undefined> {
const model = await this.selectFromQuery.executeTakeFirst()
if (model === undefined)
throw new ModelNotFoundException(404, 'No ${modelName}Model results found for query')
const result = await instance.mapWith(model)
const result = await this.mapWith(model)
const data = new ${modelName}Model(result as ${modelName}Type)
return data
}
async firstOrFail(): Promise<${modelName}Model | undefined> {
return await this.applyFirstOrFail()
}
static async firstOrFail(): Promise<${modelName}Model | undefined> {
const instance = new ${modelName}Model(null)
return await instance.applyFirstOrFail()
}
async mapWith(model: ${modelName}Type): Promise<${modelName}Type> {
${relationStringThisMany}
Expand Down
22 changes: 13 additions & 9 deletions storage/framework/orm/src/models/AccessToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,25 +253,29 @@ export class AccessTokenModel {
return await instance.applyFirst()
}

async firstOrFail(): Promise<AccessTokenModel | undefined> {
return await AccessTokenModel.firstOrFail()
}

static async firstOrFail(): Promise<AccessTokenModel | undefined> {
const instance = new AccessTokenModel(null)

const model = await instance.selectFromQuery.executeTakeFirst()
async applyFirstOrFail(): Promise<AccessTokenModel | undefined> {
const model = await this.selectFromQuery.executeTakeFirst()

if (model === undefined)
throw new ModelNotFoundException(404, 'No AccessTokenModel results found for query')

const result = await instance.mapWith(model)
const result = await this.mapWith(model)

const data = new AccessTokenModel(result as AccessTokenType)

return data
}

async firstOrFail(): Promise<AccessTokenModel | undefined> {
return await this.applyFirstOrFail()
}

static async firstOrFail(): Promise<AccessTokenModel | undefined> {
const instance = new AccessTokenModel(null)

return await instance.applyFirstOrFail()
}

async mapWith(model: AccessTokenType): Promise<AccessTokenType> {
if (this.withRelations.includes('team')) {
model.team = await this.teamBelong()
Expand Down
22 changes: 13 additions & 9 deletions storage/framework/orm/src/models/Activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,25 +268,29 @@ export class ActivityModel {
return await instance.applyFirst()
}

async firstOrFail(): Promise<ActivityModel | undefined> {
return await ActivityModel.firstOrFail()
}

static async firstOrFail(): Promise<ActivityModel | undefined> {
const instance = new ActivityModel(null)

const model = await instance.selectFromQuery.executeTakeFirst()
async applyFirstOrFail(): Promise<ActivityModel | undefined> {
const model = await this.selectFromQuery.executeTakeFirst()

if (model === undefined)
throw new ModelNotFoundException(404, 'No ActivityModel results found for query')

const result = await instance.mapWith(model)
const result = await this.mapWith(model)

const data = new ActivityModel(result as ActivityType)

return data
}

async firstOrFail(): Promise<ActivityModel | undefined> {
return await this.applyFirstOrFail()
}

static async firstOrFail(): Promise<ActivityModel | undefined> {
const instance = new ActivityModel(null)

return await instance.applyFirstOrFail()
}

async mapWith(model: ActivityType): Promise<ActivityType> {
return model
}
Expand Down
22 changes: 13 additions & 9 deletions storage/framework/orm/src/models/Deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,25 +290,29 @@ export class DeploymentModel {
return await instance.applyFirst()
}

async firstOrFail(): Promise<DeploymentModel | undefined> {
return await DeploymentModel.firstOrFail()
}

static async firstOrFail(): Promise<DeploymentModel | undefined> {
const instance = new DeploymentModel(null)

const model = await instance.selectFromQuery.executeTakeFirst()
async applyFirstOrFail(): Promise<DeploymentModel | undefined> {
const model = await this.selectFromQuery.executeTakeFirst()

if (model === undefined)
throw new ModelNotFoundException(404, 'No DeploymentModel results found for query')

const result = await instance.mapWith(model)
const result = await this.mapWith(model)

const data = new DeploymentModel(result as DeploymentType)

return data
}

async firstOrFail(): Promise<DeploymentModel | undefined> {
return await this.applyFirstOrFail()
}

static async firstOrFail(): Promise<DeploymentModel | undefined> {
const instance = new DeploymentModel(null)

return await instance.applyFirstOrFail()
}

async mapWith(model: DeploymentType): Promise<DeploymentType> {
if (this.withRelations.includes('user')) {
model.user = await this.userBelong()
Expand Down
22 changes: 13 additions & 9 deletions storage/framework/orm/src/models/Error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,25 +249,29 @@ export class ErrorModel {
return await instance.applyFirst()
}

async firstOrFail(): Promise<ErrorModel | undefined> {
return await ErrorModel.firstOrFail()
}

static async firstOrFail(): Promise<ErrorModel | undefined> {
const instance = new ErrorModel(null)

const model = await instance.selectFromQuery.executeTakeFirst()
async applyFirstOrFail(): Promise<ErrorModel | undefined> {
const model = await this.selectFromQuery.executeTakeFirst()

if (model === undefined)
throw new ModelNotFoundException(404, 'No ErrorModel results found for query')

const result = await instance.mapWith(model)
const result = await this.mapWith(model)

const data = new ErrorModel(result as ErrorType)

return data
}

async firstOrFail(): Promise<ErrorModel | undefined> {
return await this.applyFirstOrFail()
}

static async firstOrFail(): Promise<ErrorModel | undefined> {
const instance = new ErrorModel(null)

return await instance.applyFirstOrFail()
}

async mapWith(model: ErrorType): Promise<ErrorType> {
return model
}
Expand Down
22 changes: 13 additions & 9 deletions storage/framework/orm/src/models/FailedJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,25 +249,29 @@ export class FailedJobModel {
return await instance.applyFirst()
}

async firstOrFail(): Promise<FailedJobModel | undefined> {
return await FailedJobModel.firstOrFail()
}

static async firstOrFail(): Promise<FailedJobModel | undefined> {
const instance = new FailedJobModel(null)

const model = await instance.selectFromQuery.executeTakeFirst()
async applyFirstOrFail(): Promise<FailedJobModel | undefined> {
const model = await this.selectFromQuery.executeTakeFirst()

if (model === undefined)
throw new ModelNotFoundException(404, 'No FailedJobModel results found for query')

const result = await instance.mapWith(model)
const result = await this.mapWith(model)

const data = new FailedJobModel(result as FailedJobType)

return data
}

async firstOrFail(): Promise<FailedJobModel | undefined> {
return await this.applyFirstOrFail()
}

static async firstOrFail(): Promise<FailedJobModel | undefined> {
const instance = new FailedJobModel(null)

return await instance.applyFirstOrFail()
}

async mapWith(model: FailedJobType): Promise<FailedJobType> {
return model
}
Expand Down
22 changes: 13 additions & 9 deletions storage/framework/orm/src/models/Job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,25 +249,29 @@ export class JobModel {
return await instance.applyFirst()
}

async firstOrFail(): Promise<JobModel | undefined> {
return await JobModel.firstOrFail()
}

static async firstOrFail(): Promise<JobModel | undefined> {
const instance = new JobModel(null)

const model = await instance.selectFromQuery.executeTakeFirst()
async applyFirstOrFail(): Promise<JobModel | undefined> {
const model = await this.selectFromQuery.executeTakeFirst()

if (model === undefined)
throw new ModelNotFoundException(404, 'No JobModel results found for query')

const result = await instance.mapWith(model)
const result = await this.mapWith(model)

const data = new JobModel(result as JobType)

return data
}

async firstOrFail(): Promise<JobModel | undefined> {
return await this.applyFirstOrFail()
}

static async firstOrFail(): Promise<JobModel | undefined> {
const instance = new JobModel(null)

return await instance.applyFirstOrFail()
}

async mapWith(model: JobType): Promise<JobType> {
return model
}
Expand Down
22 changes: 13 additions & 9 deletions storage/framework/orm/src/models/PaymentMethod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,25 +299,29 @@ export class PaymentMethodModel {
return await instance.applyFirst()
}

async firstOrFail(): Promise<PaymentMethodModel | undefined> {
return await PaymentMethodModel.firstOrFail()
}

static async firstOrFail(): Promise<PaymentMethodModel | undefined> {
const instance = new PaymentMethodModel(null)

const model = await instance.selectFromQuery.executeTakeFirst()
async applyFirstOrFail(): Promise<PaymentMethodModel | undefined> {
const model = await this.selectFromQuery.executeTakeFirst()

if (model === undefined)
throw new ModelNotFoundException(404, 'No PaymentMethodModel results found for query')

const result = await instance.mapWith(model)
const result = await this.mapWith(model)

const data = new PaymentMethodModel(result as PaymentMethodType)

return data
}

async firstOrFail(): Promise<PaymentMethodModel | undefined> {
return await this.applyFirstOrFail()
}

static async firstOrFail(): Promise<PaymentMethodModel | undefined> {
const instance = new PaymentMethodModel(null)

return await instance.applyFirstOrFail()
}

async mapWith(model: PaymentMethodType): Promise<PaymentMethodType> {
if (this.withRelations.includes('transactions')) {
model.transactions = await this.transactionsHasMany()
Expand Down
22 changes: 13 additions & 9 deletions storage/framework/orm/src/models/Post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,25 +235,29 @@ export class PostModel {
return await instance.applyFirst()
}

async firstOrFail(): Promise<PostModel | undefined> {
return await PostModel.firstOrFail()
}

static async firstOrFail(): Promise<PostModel | undefined> {
const instance = new PostModel(null)

const model = await instance.selectFromQuery.executeTakeFirst()
async applyFirstOrFail(): Promise<PostModel | undefined> {
const model = await this.selectFromQuery.executeTakeFirst()

if (model === undefined)
throw new ModelNotFoundException(404, 'No PostModel results found for query')

const result = await instance.mapWith(model)
const result = await this.mapWith(model)

const data = new PostModel(result as PostType)

return data
}

async firstOrFail(): Promise<PostModel | undefined> {
return await this.applyFirstOrFail()
}

static async firstOrFail(): Promise<PostModel | undefined> {
const instance = new PostModel(null)

return await instance.applyFirstOrFail()
}

async mapWith(model: PostType): Promise<PostType> {
if (this.withRelations.includes('user')) {
model.user = await this.userBelong()
Expand Down
22 changes: 13 additions & 9 deletions storage/framework/orm/src/models/Product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,25 +277,29 @@ export class ProductModel {
return await instance.applyFirst()
}

async firstOrFail(): Promise<ProductModel | undefined> {
return await ProductModel.firstOrFail()
}

static async firstOrFail(): Promise<ProductModel | undefined> {
const instance = new ProductModel(null)

const model = await instance.selectFromQuery.executeTakeFirst()
async applyFirstOrFail(): Promise<ProductModel | undefined> {
const model = await this.selectFromQuery.executeTakeFirst()

if (model === undefined)
throw new ModelNotFoundException(404, 'No ProductModel results found for query')

const result = await instance.mapWith(model)
const result = await this.mapWith(model)

const data = new ProductModel(result as ProductType)

return data
}

async firstOrFail(): Promise<ProductModel | undefined> {
return await this.applyFirstOrFail()
}

static async firstOrFail(): Promise<ProductModel | undefined> {
const instance = new ProductModel(null)

return await instance.applyFirstOrFail()
}

async mapWith(model: ProductType): Promise<ProductType> {
return model
}
Expand Down
Loading

0 comments on commit c346937

Please sign in to comment.