File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -115,14 +115,17 @@ export async function createField({
115115
116116 const createdField = await prisma . $transaction ( async ( tx ) => {
117117 /**
118- * INSERT AT HEAD
118+ * INSERT AT TAIL
119119 */
120120 if ( ! body . prevFieldId ) {
121- const currentHead = await tx . formFields . findFirst ( {
121+ const lastField = await tx . formFields . findFirst ( {
122122 where : {
123123 formId : params . formId ,
124- prevFieldId : null ,
125124 } ,
125+ orderBy : {
126+ createdAt : "desc" ,
127+ } ,
128+ take : 1 ,
126129 } ) ;
127130
128131 const created = await tx . formFields . create ( {
@@ -134,17 +137,10 @@ export async function createField({
134137 validation : body . validation ?? undefined ,
135138 options : body . options ?? undefined ,
136139 formId : params . formId ,
137- prevFieldId : null ,
140+ prevFieldId : lastField ?. id ?? null ,
138141 } ,
139142 } ) ;
140143
141- if ( currentHead ) {
142- await tx . formFields . update ( {
143- where : { id : currentHead . id } ,
144- data : { prevFieldId : created . id } ,
145- } ) ;
146- }
147-
148144 return created ;
149145 }
150146
You can’t perform that action at this time.
0 commit comments