Skip to content
This repository was archived by the owner on Jan 24, 2023. It is now read-only.

Commit cc4b9fe

Browse files
committed
fix(server): Bugs fixed
1 parent 9799b92 commit cc4b9fe

13 files changed

Lines changed: 129 additions & 61 deletions

File tree

packages/@simpli/cli-scaffold/generator/template/src/views/LoginView.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<div class="verti w-window h-window items-center">
44
<form @submit.prevent="signIn(model)" class="verti w-300 elevated p-30">
55
<h2 class="mt-0">{{ $t("view.login.subtitle") }}</h2>
6-
<input v-model="model.account" class="mb-10" type="text" :placeholder="$t('view.login.account')" required autofocus/>
7-
<input v-model="model.password" class="mb-10" type="password" :placeholder="$t('view.login.password')" required>
6+
<input v-model="model.<%-rootOptions.scaffoldSetup.auth.accountAttrName%>" class="mb-10" type="text" :placeholder="$t('view.login.account')" required autofocus/>
7+
<input v-model="model.<%-rootOptions.scaffoldSetup.auth.passwordAttrName%>" class="mb-10" type="password" :placeholder="$t('view.login.password')" required>
88
<button class="accent" type="submit">{{ $t("view.login.signin") }}</button>
99
</form>
1010
</div>

packages/@simpli/cli-server/generator/injected/src/main/dao/TemplateDao.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,8 @@ class <%-table.modelName%>Dao(con: Connection, lang: LanguageHolder) : Dao(con,
177177
<%_ for (var i in table.exceptPrimaryColumns) { var column = table.exceptPrimaryColumns[i] _%>
178178
<%_ if (column.isCreatedAt) { _%>
179179
<%_ } else if (!column.isUpdatedAt) { _%>
180-
<%-table.instanceName%>.<%-column.name%>,
181-
<%_ } _%>
180+
<%-table.instanceName%>.<%-column.name%><%-i < table.exceptPrimaryColumns.length - 1 ? ',' : ''%>
182181
<%_ } _%>
183-
<%_ for (var i in table.primaryColumns) { var column = table.primaryColumns[i] _%>
184-
<%-table.instanceName%>.<%-column.name%><%-i < table.primaryColumns.length - 1 ? ',' : ''%>
185182
<%_ } _%>
186183
).key
187184
}

packages/@simpli/cli-server/generator/injected/src/main/module/process/LoginService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import com.google.gson.Gson
1010
import java.sql.Connection
1111
import <%-packageAddress%>.<%-moduleName%>.response.LoginResp
1212
import <%-packageAddress%>.exception.HttpException
13-
import <%-packageAddress%>.model.User
13+
import <%-packageAddress%>.model.<%-userTable.modelName%>
1414
import com.simpli.model.LanguageHolder
1515
import com.simpli.model.RespException
1616
import com.simpli.tools.SecurityUtils

packages/@simpli/cli-server/generator/injected/src/main/module/process/TemplateProcess.kt

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@ package <%-packageAddress%>.<%-moduleName%>.process
44

55
import <%-packageAddress%>.model.<%-table.modelName%>
66
import <%-packageAddress%>.<%-moduleName%>.response.<%-table.modelName%>Resp
7-
import <%-packageAddress%>.dao.<%-table.modelName%>Dao
8-
<%_ for (var i in table.validDistinctRelations) { var relation = table.validDistinctRelations[i] _%>
9-
import <%-packageAddress%>.dao.<%-relation.referencedTableModelName%>Dao
10-
<%_ if (relation.isManyToMany) { _%>
11-
import <%-packageAddress%>.dao.<%-relation.pivot.tableModelName%>Dao
12-
<%_ } _%>
7+
<%_ for (var i in table.daoModels) { var obj = table.daoModels[i] _%>
8+
import <%-packageAddress%>.dao.<%-obj.modelName%>Dao
139
<%_ } _%>
1410
import <%-packageAddress%>.exception.HttpException
1511
import com.google.common.base.Strings
@@ -64,38 +60,31 @@ class <%-table.modelName%>Process(private val con: Connection, private val lang:
6460
//TODO: review generated method
6561
loginS.allowAccess(token)
6662

67-
val <%-table.instanceName%>Dao = <%-table.modelName%>Dao(con, lang)
68-
<%_ for (var i in table.validDistinctRelations) { var relation = table.validDistinctRelations[i] _%>
69-
<%_ if (!relation.isManyToMany) { _%>
70-
val <%-relation.name%>Dao = <%-relation.referencedTableModelName%>Dao(con, lang)
71-
<%_ } else { _%>
72-
val <%-table.manyToMany.crossRelationInstanceName%>Dao = <%-table.manyToMany.crossRelationModelName%>Dao(con, lang)
73-
val <%-table.manyToMany.pivotInstanceName%>Dao = <%-table.manyToMany.pivotModelName%>Dao(con, lang)
74-
<%_ } _%>
63+
<%_ for (var i in table.daoModels) { var obj = table.daoModels[i] _%>
64+
val <%-obj.name%>Dao = <%-obj.modelName%>Dao(con, lang)
7565
<%_ } _%>
7666

7767
val resp = <%-table.modelName%>Resp()
7868

7969
if (<%-table.primariesByConditions()%>) {
8070
val <%-table.instanceName%> = <%-table.instanceName%>Dao.getOne(<%-table.primariesByComma(true)%>)
81-
<%_ if (table.hasPivot) { _%>
71+
<%_ for (var i in table.manyToMany) { var m2m = table.manyToMany[i] _%>
8272
if (<%-table.instanceName%> != null) {
83-
<%-table.instanceName%>.<%-table.manyToMany.pivotInstanceName%> = tagPrincipalDao.list<%-table.manyToMany.crossRelationModelName%>Of<%-table.modelName%>(<%-table.idColumn.name%>)
73+
<%-table.instanceName%>.<%-m2m.pivotInstanceName%> = <%-m2m.pivotInstanceName%>Dao.list<%-m2m.crossRelationModelName%>Of<%-table.modelName%>(<%-table.idColumn.name%>)
8474
}
8575
<%_ } _%>
8676
resp.<%-table.instanceName%> = <%-table.instanceName%>
8777
}
8878

8979
<%_ for (var i in table.validDistinctRelations) { var relation = table.validDistinctRelations[i] _%>
9080
<%_ if (!relation.isManyToMany) { _%>
91-
resp.all<%-relation.referencedTableModelName%> = <%-relation.name%>Dao.list()
92-
<%_ } else { _%>
93-
resp.all<%-relation.referencedTableModelName%> = <%-table.manyToMany.crossRelationInstanceName%>Dao.list()
81+
resp.all<%-relation.referencedTableModelName%> = <%-relation.referencedTableInstanceName%>Dao.list()
9482
<%_ } _%>
9583
<%_ } _%>
96-
<%_ if (table.validDistinctRelations.length > 0) { _%>
97-
84+
<%_ for (var i in table.manyToMany) { var m2m = table.manyToMany[i] _%>
85+
resp.all<%-m2m.crossRelationModelName%> = <%-m2m.crossRelationInstanceName%>Dao.list()
9886
<%_ } _%>
87+
9988
return resp
10089
}
10190

@@ -140,14 +129,14 @@ class <%-table.modelName%>Process(private val con: Connection, private val lang:
140129
}
141130
<%_ } _%>
142131

143-
<%_ if (table.hasPivot) { _%>
144-
val <%-table.manyToMany.pivotInstanceName%>Dao = <%-table.manyToMany.pivotModelName%>Dao(con, lang)
132+
<%_ for (var i in table.manyToMany) { var m2m = table.manyToMany[i] _%>
133+
val <%-m2m.pivotInstanceName%>Dao = <%-m2m.pivotModelName%>Dao(con, lang)
145134

146-
<%-table.manyToMany.pivotInstanceName%>Dao.removeAllFrom<%-table.modelName%>(id<%-table.modelName%>)
135+
<%-m2m.pivotInstanceName%>Dao.removeAllFrom<%-table.modelName%>(id<%-table.modelName%>)
147136

148-
<%-table.instanceName%>.<%-table.manyToMany.pivotInstanceName%>?.let { list ->
149-
for (<%-table.manyToMany.crossRelationInstanceName%> in list) {
150-
<%-table.manyToMany.pivotInstanceName%>Dao.insert(<%-table.manyToMany.crossRelationInstanceName%>.<%-table.manyToMany.crossRelationColumnName%>, id<%-table.modelName%>)
137+
<%-table.instanceName%>.<%-m2m.pivotInstanceName%>?.let { list ->
138+
for (<%-m2m.crossRelationInstanceName%> in list) {
139+
<%-m2m.pivotInstanceName%>Dao.insert(<%-options.serverSetup.insertPivotByComma(table, m2m)%>)
151140
}
152141
}
153142

packages/@simpli/cli-server/generator/injected/src/main/module/response/TemplateResp.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ package <%-packageAddress%>.<%-moduleName%>.response
55
import io.swagger.annotations.ApiModelProperty
66
import <%-packageAddress%>.model.<%-table.modelName%>
77
<%_ for (var i in table.validDistinctRelations) { var relation = table.validDistinctRelations[i] _%>
8+
<%_ if (relation.referencedTableModelName !== table.modelName) { _%>
89
import <%-packageAddress%>.model.<%-relation.referencedTableModelName%>
910
<%_ } _%>
11+
<%_ } _%>
1012

1113
/**
1214
* Response of model <%-table.modelName%>

packages/@simpli/cli-server/generator/injected/src/test/model/TemplateTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import org.junit.Assert.*
1313
*/
1414
class PrincipalTest {
1515

16-
1716
@Test(expected = RespException::class)
1817
fun testValidateNoIdGrupoDoPrincipalFk() {
1918
val principal = Principal()

packages/@simpli/cli/lib/scaffold/Swagger.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,29 @@ module.exports = class Swagger {
219219
process.exit(1)
220220
}
221221

222+
const { accountAttrName } = await inquirer.prompt([
223+
{
224+
name: 'accountAttrName',
225+
type: 'list',
226+
choices: loginHolderModel.attrs.map((api) => api.name),
227+
default: loginHolderModel.attrs.findIndex((api) => !!['account', 'email'].find((name) => api.name === name)) || 0,
228+
message: 'Which of these attributes is the account column?'
229+
}
230+
])
231+
const { passwordAttrName } = await inquirer.prompt([
232+
{
233+
name: 'passwordAttrName',
234+
type: 'list',
235+
choices: loginHolderModel.attrs.map((api) => api.name),
236+
default: loginHolderModel.attrs.findIndex((api) => !!['password', 'senha'].find((name) => api.name === name)) || 0,
237+
message: 'Which of these attributes is the password column?'
238+
}
239+
])
240+
222241
const auth = new Auth()
223242

243+
auth.accountAttrName = accountAttrName
244+
auth.passwordAttrName = passwordAttrName
224245
auth.api.signIn = signInApi
225246
auth.api.auth = authApi
226247
auth.model.loginHolder = loginHolderModel

packages/@simpli/cli/lib/scaffold/setup/Auth.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const camelCase = require('lodash.camelcase')
33

44
module.exports = class Auth {
55
constructor () {
6+
this.accountAttrName = null
7+
this.passwordAttrName = null
68
this.api = {
79
signIn: null,
810
auth: null

packages/@simpli/cli/lib/server/Database.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ module.exports = class Database {
214214
name: 'accountColumnName',
215215
type: 'list',
216216
choices: availableColumns.map((column) => column.name),
217-
default: availableColumns.findIndex((column) => column.name === 'email') || 0,
217+
default: availableColumns.findIndex((column) => !!['account', 'email'].find((name) => column.name === name)) || 0,
218218
message: 'Which of these columns is the account column?'
219219
}
220220
])
@@ -223,7 +223,7 @@ module.exports = class Database {
223223
name: 'passwordColumnName',
224224
type: 'list',
225225
choices: availableColumns.map((column) => column.name),
226-
default: availableColumns.findIndex((column) => column.name === 'user') || 0,
226+
default: availableColumns.findIndex((column) => !!['password', 'senha'].find((name) => column.name === name)) || 0,
227227
message: 'Which of these columns is the password column?'
228228
}
229229
])
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = class ManyToMany {
2+
constructor () {
3+
this.pivotTableName = null
4+
this.pivotModelName = null
5+
this.pivotInstanceName = null
6+
this.crossRelationTableName = null
7+
this.crossRelationModelName = null
8+
this.crossRelationInstanceName = null
9+
this.crossRelationColumnName = null
10+
}
11+
}

0 commit comments

Comments
 (0)