Skip to content

Commit

Permalink
fixed issue excluding getters from model definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgobich committed Jun 8, 2024
1 parent 6960a01 commit 97e30d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ import AccountTypeDto from '#dtos/account_type'
import PayeeDto from '#dtos/payee'
import StockDto from '#dtos/stock'
import TransactionDto from '#dtos/transaction'
import { AccountGroupConfig } from '#config/account'

export default class AccountDto {
declare id: number
Expand All @@ -251,6 +252,10 @@ export default class AccountDto {
declare payee: PayeeDto | null
declare stocks: StockDto[]
declare transactions: TransactionDto[]
declare accountGroup: AccountGroupConfig
declare isCreditIncrease: boolean
declare isBudgetable: boolean
declare balanceDisplay: string

constructor(account: Account) {
this.id = account.id
Expand All @@ -270,6 +275,10 @@ export default class AccountDto {
this.payee = account.payee && new PayeeDto(account.payee)
this.stocks = StockDto.fromArray(account.stocks)
this.transactions = TransactionDto.fromArray(account.transactions)
this.accountGroup = account.accountGroup
this.isCreditIncrease = account.isCreditIncrease
this.isBudgetable = account.isBudgetable
this.balanceDisplay = account.balanceDisplay
}

static fromArray(accounts: Account[]) {
Expand All @@ -285,8 +294,6 @@ It's got the
- Nullable property's nullability
- Unmapped property from our Model, plus it's default value
- Relationships converted into DTO representations
- Getters and their types, when specified. If types are inferred, the type will default to string or boolean if variable name starts with `is`
- Constructor value setters for all of the above
- A helper method `fromArray` that'll normalize to an empty array if need be

What it doesn't have
- The getters, we're working on it though.
8 changes: 2 additions & 6 deletions services/file_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ export default class FileService {
static async readDeclarations(filePath: string) {
const contents = await readFile(filePath, 'utf8')
const fileLines = contents.split('\n')
// const definitions = fileLines.filter(
// (line) => line.includes('declare ') || line.includes('public ') || line.includes('get ') ||
// )
const classStartIndex = fileLines.findIndex((line) => line.includes(' extends BaseModel '))
const classEndIndex = fileLines.findLastIndex((line) => string.condenseWhitespace(line) === '}')

Expand All @@ -35,15 +32,14 @@ export default class FileService {
let isInBlock: boolean = false
const definitions = classLines.filter((line) => {
const propertyMatch = line.match(/^(declare |public |get |[0-9A-z])+/)
const isDefinition = propertyMatch && !isInBlock

if (line.endsWith('{')) isInBlock = true
if (line.startsWith('}') && isInBlock) isInBlock = false

return propertyMatch && !isInBlock
return isDefinition
})

console.log({ classLines, definitions, classStartIndex, classEndIndex, fileLines })

return { definitions, fileLines }
}
}

0 comments on commit 97e30d0

Please sign in to comment.