-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding ability to backfill invoices for a user as-needed.
- Loading branch information
Showing
11 changed files
with
226 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext' | ||
import User from 'App/Models/User' | ||
import InvoiceStoreValidator from 'App/Validators/InvoiceStoreValidator' | ||
import { DateTime } from 'luxon' | ||
|
||
export default class InvoicesController { | ||
public async index({}: HttpContextContract) {} | ||
|
||
public async create({}: HttpContextContract) {} | ||
|
||
public async store({ request, response, params }: HttpContextContract) { | ||
const { periodStartAt, periodEndAt, ...data } = await request.validate(InvoiceStoreValidator) | ||
const user = await User.findOrFail(params.id) | ||
|
||
await user.related('invoices').create({ | ||
...data, | ||
paid: true, | ||
periodStartAt: periodStartAt ? DateTime.fromSeconds(periodStartAt) : undefined, | ||
periodEndAt: periodEndAt ? DateTime.fromSeconds(periodEndAt) : undefined | ||
}) | ||
|
||
return response.redirect().back() | ||
} | ||
|
||
public async show({}: HttpContextContract) {} | ||
|
||
public async edit({}: HttpContextContract) {} | ||
|
||
public async update({}: HttpContextContract) {} | ||
|
||
public async destroy({}: HttpContextContract) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { DateTime } from 'luxon' | ||
import { BaseModel, BelongsTo, belongsTo, column } from '@ioc:Adonis/Lucid/Orm' | ||
import User from './User' | ||
|
||
export default class Invoice extends BaseModel { | ||
@column({ isPrimary: true }) | ||
public id: number | ||
|
||
@column() | ||
public userId: number | ||
|
||
@column() | ||
public invoiceId: string | ||
|
||
@column() | ||
public invoiceNumber: string | ||
|
||
@column() | ||
public chargeId: string | ||
|
||
@column() | ||
public amountDue: number | ||
|
||
@column() | ||
public amountPaid: number | ||
|
||
@column() | ||
public amountRemaining: number | ||
|
||
@column() | ||
public status: string | ||
|
||
@column() | ||
public paid: boolean | ||
|
||
@column.dateTime() | ||
public periodStartAt: DateTime | ||
|
||
@column.dateTime() | ||
public periodEndAt: DateTime | ||
|
||
@column.dateTime({ autoCreate: true }) | ||
public createdAt: DateTime | ||
|
||
@column.dateTime({ autoCreate: true, autoUpdate: true }) | ||
public updatedAt: DateTime | ||
|
||
@belongsTo(() => User) | ||
public user: BelongsTo<typeof User> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { schema, rules } from '@ioc:Adonis/Core/Validator' | ||
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext' | ||
|
||
export default class InvoiceStoreValidator { | ||
constructor(protected ctx: HttpContextContract) {} | ||
|
||
/* | ||
* Define schema to validate the "shape", "type", "formatting" and "integrity" of data. | ||
* | ||
* For example: | ||
* 1. The username must be of data type string. But then also, it should | ||
* not contain special characters or numbers. | ||
* ``` | ||
* schema.string({}, [ rules.alpha() ]) | ||
* ``` | ||
* | ||
* 2. The email must be of data type string, formatted as a valid | ||
* email. But also, not used by any other user. | ||
* ``` | ||
* schema.string({}, [ | ||
* rules.email(), | ||
* rules.unique({ table: 'users', column: 'email' }), | ||
* ]) | ||
* ``` | ||
*/ | ||
public schema = schema.create({ | ||
invoiceId: schema.string([rules.unique({ table: 'invoices', column: 'invoice_id' })]), | ||
invoiceNumber: schema.string(), | ||
chargeId: schema.string.optional(), | ||
amountDue: schema.number(), | ||
amountPaid: schema.number(), | ||
amountRemaining: schema.number(), | ||
status: schema.string.optional(), | ||
periodStartAt: schema.number.optional(), | ||
periodEndAt: schema.number.optional(), | ||
}) | ||
|
||
/** | ||
* Custom messages for validation failures. You can make use of dot notation `(.)` | ||
* for targeting nested fields and array expressions `(*)` for targeting all | ||
* children of an array. For example: | ||
* | ||
* { | ||
* 'profile.username.required': 'Username is required', | ||
* 'scores.*.number': 'Define scores as valid numbers' | ||
* } | ||
* | ||
*/ | ||
public messages = {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
{ | ||
"assets/app.css": "http://localhost:64876/assets/app.css", | ||
"assets/app.js": "http://localhost:64876/assets/app.js", | ||
"assets/post.js": "http://localhost:64876/assets/post.js", | ||
"assets/stream.js": "http://localhost:64876/assets/stream.js", | ||
"assets/file_manager.js": "http://localhost:64876/assets/file_manager.js", | ||
"assets/tiptap_basic.js": "http://localhost:64876/assets/tiptap_basic.js", | ||
"assets/studio.posts.editor.js": "http://localhost:64876/assets/studio.posts.editor.js", | ||
"assets/studio.collections.js": "http://localhost:64876/assets/studio.collections.js" | ||
"assets/app.css": "http://localhost:63685/assets/app.css", | ||
"assets/app.js": "http://localhost:63685/assets/app.js", | ||
"assets/post.js": "http://localhost:63685/assets/post.js", | ||
"assets/stream.js": "http://localhost:63685/assets/stream.js", | ||
"assets/file_manager.js": "http://localhost:63685/assets/file_manager.js", | ||
"assets/tiptap_basic.js": "http://localhost:63685/assets/tiptap_basic.js", | ||
"assets/studio.posts.editor.js": "http://localhost:63685/assets/studio.posts.editor.js", | ||
"assets/studio.collections.js": "http://localhost:63685/assets/studio.collections.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters