Skip to content

Commit e4d9963

Browse files
chore: wip
1 parent 43e681c commit e4d9963

File tree

17 files changed

+428
-360
lines changed

17 files changed

+428
-360
lines changed

storage/framework/core/orm/src/generate.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ export async function generateModelString(
280280
}
281281
}
282282

283-
declareFields += `public id: number \n `
283+
declareFields += `public id: number | undefined \n `
284284

285285
constructorFields += `this.id = ${formattedModelName}?.id || 1\n `
286286

@@ -736,12 +736,12 @@ export async function generateModelString(
736736
protected updateFromQuery: any
737737
protected deleteFromQuery: any
738738
protected hasSelect: boolean
739-
private customColumns: Record<string, any> = {}
739+
private customColumns: Record<string, unknown> = {}
740740
${declareFields}
741741
constructor(${formattedModelName}: Partial<${modelName}Type> | null) {
742-
${constructorFields}
743-
744742
if (${formattedModelName}) {
743+
${constructorFields}
744+
745745
Object.keys(${formattedModelName}).forEach(key => {
746746
if (!(key in this)) {
747747
this.customColumns[key] = (user as ${modelName}JsonResponse)[key]
@@ -1524,21 +1524,21 @@ export async function generateModelString(
15241524
const filteredValues = Object.fromEntries(
15251525
Object.entries(${formattedModelName}).filter(([key]) => this.fillable.includes(key)),
15261526
) as New${modelName}
1527-
1528-
if (this.id === undefined) {
1529-
this.updateFromQuery.set(filteredValues).execute()
1530-
}
1531-
1527+
15321528
await db.updateTable('${tableName}')
15331529
.set(filteredValues)
15341530
.where('id', '=', this.id)
15351531
.executeTakeFirst()
1536-
1537-
const model = await this.find(this.id)
1538-
1539-
${mittUpdateStatement}
1540-
1541-
return model
1532+
1533+
if (this.id) {
1534+
const model = await this.find(this.id)
1535+
1536+
${mittUpdateStatement}
1537+
1538+
return model
1539+
}
1540+
1541+
return undefined
15421542
}
15431543
15441544
async forceUpdate(${formattedModelName}: ${modelName}Update): Promise<${modelName}Model | undefined> {
@@ -1551,12 +1551,16 @@ export async function generateModelString(
15511551
.where('id', '=', this.id)
15521552
.executeTakeFirst()
15531553
1554-
const model = await this.find(this.id)
1554+
if (this.id) {
1555+
const model = await this.find(this.id)
15551556
15561557
15571558
${mittUpdateStatement}
15581559
1559-
return model
1560+
return model
1561+
}
1562+
1563+
return undefined
15601564
}
15611565
15621566
async save(): Promise<void> {

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

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ export class AccessTokenModel {
5858
protected updateFromQuery: any
5959
protected deleteFromQuery: any
6060
protected hasSelect: boolean
61-
private customColumns: Record<string, any> = {}
61+
private customColumns: Record<string, unknown> = {}
6262
public team_id: number | undefined
6363
public team: TeamModel | undefined
64-
public id: number
64+
public id: number | undefined
6565
public name: string | undefined
6666
public token: string | undefined
6767
public plain_text_token: string | undefined
@@ -71,19 +71,19 @@ export class AccessTokenModel {
7171
public updated_at: Date | undefined
7272

7373
constructor(accesstoken: Partial<AccessTokenType> | null) {
74-
this.team_id = accesstoken?.team_id
75-
this.team = accesstoken?.team
76-
this.id = accesstoken?.id || 1
77-
this.name = accesstoken?.name
78-
this.token = accesstoken?.token
79-
this.plain_text_token = accesstoken?.plain_text_token
80-
this.abilities = accesstoken?.abilities
74+
if (accesstoken) {
75+
this.team_id = accesstoken?.team_id
76+
this.team = accesstoken?.team
77+
this.id = accesstoken?.id || 1
78+
this.name = accesstoken?.name
79+
this.token = accesstoken?.token
80+
this.plain_text_token = accesstoken?.plain_text_token
81+
this.abilities = accesstoken?.abilities
8182

82-
this.created_at = accesstoken?.created_at
83+
this.created_at = accesstoken?.created_at
8384

84-
this.updated_at = accesstoken?.updated_at
85+
this.updated_at = accesstoken?.updated_at
8586

86-
if (accesstoken) {
8787
Object.keys(accesstoken).forEach((key) => {
8888
if (!(key in this)) {
8989
this.customColumns[key] = (user as AccessTokenJsonResponse)[key]
@@ -865,18 +865,18 @@ export class AccessTokenModel {
865865
Object.entries(accesstoken).filter(([key]) => this.fillable.includes(key)),
866866
) as NewAccessToken
867867

868-
if (this.id === undefined) {
869-
this.updateFromQuery.set(filteredValues).execute()
870-
}
871-
872868
await db.updateTable('personal_access_tokens')
873869
.set(filteredValues)
874870
.where('id', '=', this.id)
875871
.executeTakeFirst()
876872

877-
const model = await this.find(this.id)
873+
if (this.id) {
874+
const model = await this.find(this.id)
878875

879-
return model
876+
return model
877+
}
878+
879+
return undefined
880880
}
881881

882882
async forceUpdate(accesstoken: AccessTokenUpdate): Promise<AccessTokenModel | undefined> {
@@ -889,9 +889,13 @@ export class AccessTokenModel {
889889
.where('id', '=', this.id)
890890
.executeTakeFirst()
891891

892-
const model = await this.find(this.id)
892+
if (this.id) {
893+
const model = await this.find(this.id)
893894

894-
return model
895+
return model
896+
}
897+
898+
return undefined
895899
}
896900

897901
async save(): Promise<void> {

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

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ export class DeploymentModel {
6363
protected updateFromQuery: any
6464
protected deleteFromQuery: any
6565
protected hasSelect: boolean
66-
private customColumns: Record<string, any> = {}
66+
private customColumns: Record<string, unknown> = {}
6767
public user_id: number | undefined
6868
public user: UserModel | undefined
69-
public id: number
69+
public id: number | undefined
7070
public uuid: string | undefined
7171
public commit_sha: string | undefined
7272
public commit_message: string | undefined
@@ -80,23 +80,23 @@ export class DeploymentModel {
8080
public updated_at: Date | undefined
8181

8282
constructor(deployment: Partial<DeploymentType> | null) {
83-
this.user_id = deployment?.user_id
84-
this.user = deployment?.user
85-
this.id = deployment?.id || 1
86-
this.uuid = deployment?.uuid
87-
this.commit_sha = deployment?.commit_sha
88-
this.commit_message = deployment?.commit_message
89-
this.branch = deployment?.branch
90-
this.status = deployment?.status
91-
this.execution_time = deployment?.execution_time
92-
this.deploy_script = deployment?.deploy_script
93-
this.terminal_output = deployment?.terminal_output
94-
95-
this.created_at = deployment?.created_at
96-
97-
this.updated_at = deployment?.updated_at
98-
9983
if (deployment) {
84+
this.user_id = deployment?.user_id
85+
this.user = deployment?.user
86+
this.id = deployment?.id || 1
87+
this.uuid = deployment?.uuid
88+
this.commit_sha = deployment?.commit_sha
89+
this.commit_message = deployment?.commit_message
90+
this.branch = deployment?.branch
91+
this.status = deployment?.status
92+
this.execution_time = deployment?.execution_time
93+
this.deploy_script = deployment?.deploy_script
94+
this.terminal_output = deployment?.terminal_output
95+
96+
this.created_at = deployment?.created_at
97+
98+
this.updated_at = deployment?.updated_at
99+
100100
Object.keys(deployment).forEach((key) => {
101101
if (!(key in this)) {
102102
this.customColumns[key] = (user as DeploymentJsonResponse)[key]
@@ -908,18 +908,18 @@ export class DeploymentModel {
908908
Object.entries(deployment).filter(([key]) => this.fillable.includes(key)),
909909
) as NewDeployment
910910

911-
if (this.id === undefined) {
912-
this.updateFromQuery.set(filteredValues).execute()
913-
}
914-
915911
await db.updateTable('deployments')
916912
.set(filteredValues)
917913
.where('id', '=', this.id)
918914
.executeTakeFirst()
919915

920-
const model = await this.find(this.id)
916+
if (this.id) {
917+
const model = await this.find(this.id)
921918

922-
return model
919+
return model
920+
}
921+
922+
return undefined
923923
}
924924

925925
async forceUpdate(deployment: DeploymentUpdate): Promise<DeploymentModel | undefined> {
@@ -932,9 +932,13 @@ export class DeploymentModel {
932932
.where('id', '=', this.id)
933933
.executeTakeFirst()
934934

935-
const model = await this.find(this.id)
935+
if (this.id) {
936+
const model = await this.find(this.id)
936937

937-
return model
938+
return model
939+
}
940+
941+
return undefined
938942
}
939943

940944
async save(): Promise<void> {

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

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ export class ErrorModel {
5454
protected updateFromQuery: any
5555
protected deleteFromQuery: any
5656
protected hasSelect: boolean
57-
private customColumns: Record<string, any> = {}
58-
public id: number
57+
private customColumns: Record<string, unknown> = {}
58+
public id: number | undefined
5959
public type: string | undefined
6060
public message: string | undefined
6161
public stack: string | undefined
@@ -66,18 +66,18 @@ export class ErrorModel {
6666
public updated_at: Date | undefined
6767

6868
constructor(error: Partial<ErrorType> | null) {
69-
this.id = error?.id || 1
70-
this.type = error?.type
71-
this.message = error?.message
72-
this.stack = error?.stack
73-
this.status = error?.status
74-
this.additional_info = error?.additional_info
69+
if (error) {
70+
this.id = error?.id || 1
71+
this.type = error?.type
72+
this.message = error?.message
73+
this.stack = error?.stack
74+
this.status = error?.status
75+
this.additional_info = error?.additional_info
7576

76-
this.created_at = error?.created_at
77+
this.created_at = error?.created_at
7778

78-
this.updated_at = error?.updated_at
79+
this.updated_at = error?.updated_at
7980

80-
if (error) {
8181
Object.keys(error).forEach((key) => {
8282
if (!(key in this)) {
8383
this.customColumns[key] = (user as ErrorJsonResponse)[key]
@@ -863,18 +863,18 @@ export class ErrorModel {
863863
Object.entries(error).filter(([key]) => this.fillable.includes(key)),
864864
) as NewError
865865

866-
if (this.id === undefined) {
867-
this.updateFromQuery.set(filteredValues).execute()
868-
}
869-
870866
await db.updateTable('errors')
871867
.set(filteredValues)
872868
.where('id', '=', this.id)
873869
.executeTakeFirst()
874870

875-
const model = await this.find(this.id)
871+
if (this.id) {
872+
const model = await this.find(this.id)
876873

877-
return model
874+
return model
875+
}
876+
877+
return undefined
878878
}
879879

880880
async forceUpdate(error: ErrorUpdate): Promise<ErrorModel | undefined> {
@@ -887,9 +887,13 @@ export class ErrorModel {
887887
.where('id', '=', this.id)
888888
.executeTakeFirst()
889889

890-
const model = await this.find(this.id)
890+
if (this.id) {
891+
const model = await this.find(this.id)
891892

892-
return model
893+
return model
894+
}
895+
896+
return undefined
893897
}
894898

895899
async save(): Promise<void> {

0 commit comments

Comments
 (0)