MailDomain: fix 0 to null user_id conversion
This commit is contained in:
parent
08a34561e5
commit
0306180321
|
@ -100,10 +100,7 @@ export default class MailboxBackendController extends Controller {
|
|||
}
|
||||
|
||||
protected async postAddDomain(req: Request, res: Response): Promise<void> {
|
||||
const domain = MailDomain.create({
|
||||
name: req.body.name,
|
||||
user_id: req.body.user_id,
|
||||
});
|
||||
const domain = MailDomain.create(req.body);
|
||||
await domain.save();
|
||||
req.flash('success', `Domain ${domain.name} successfully added with owner ${(await domain.owner.get())?.name}`);
|
||||
res.redirectBack();
|
||||
|
|
|
@ -6,7 +6,7 @@ import MailIdentity from "./MailIdentity";
|
|||
export default class MailDomain extends Model {
|
||||
public id?: number = undefined;
|
||||
public name?: string = undefined;
|
||||
public user_id?: number = undefined;
|
||||
public user_id?: number | null = undefined;
|
||||
|
||||
public readonly owner: OneModelRelation<MailDomain, User> = new OneModelRelation(this, User, {
|
||||
localKey: 'user_id',
|
||||
|
@ -22,9 +22,7 @@ export default class MailDomain extends Model {
|
|||
|
||||
public updateWithData(data: Pick<this, keyof this> | Record<string, unknown>): void {
|
||||
super.updateWithData(data);
|
||||
if (typeof this.user_id !== 'undefined' && this.user_id <= 0) {
|
||||
this.user_id = undefined;
|
||||
}
|
||||
if (this.user_id !== null && this.user_id !== undefined && this.user_id <= 0) this.user_id = null;
|
||||
}
|
||||
|
||||
protected init(): void {
|
||||
|
|
Loading…
Reference in New Issue