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